Skip to main content

Android Toasts

Android Toasts 


  • Introduction to android toasts in Hindi
  • Methods used with android toasts in Hindi 
  • Creating android toasts in Hindi 
  • Example of android toasts in Hindi

Introduction to Android Toasts 

Android toast एक simple popup मैसेज होता है जो कुछ देर के लिए स्क्रीन पर appear होता है और automatically disappear हो जाता है। उदाहरण के लिए जब आप अपने device से कोई मैसेज भेजते है, तो आपको एक toast शो होता है, जिसमे लिखा होता है "Message sent " और वो कुछ देर बाद automatically disappear हो जाता है।

Android toasts की size उतनी ही होती है, जितना बड़ा आपका मैसेज होता है। Current activity visible होती है, आप इसके साथ interact कर सकते है।

Methods Used with Android Toasts


makeText() 

ये method एक toast create करने के काम में आता है. इस मेथड को आप Toast क्लास के object पर कॉल करते है। इस method में आप current application का context, आपका text message और toast की duration पास करते है। इसका structure नीचे दिया जा रहा है।


public static Toast makeText(context-of-Application, text-Message, duration-of-Message);


makeText() method का example नीचे दिया जा रहा है।


Toast.makeText(getApplicationContext(), "Welcome to Android in Hindi tutorials", Toast.LENGTH_SHORT);


show() 

 ये मेथड toast को display करता है। इस मेथड को आप Toast क्लास के object पर call करते है। 


toastObject.show();



setGravitiy() 

इस मेथड से आप अपने toast मैसेज को अपनी application में मन चाही position पर सेट कर सकते है।


toastObject.setGravity(200,50,200);



Creating Android Toasts     

  1. Android में toasts क्रिएट करने के लिए सबसे पहले Toast क्लास का ऑब्जेक्ट क्रिएट करेंगे ।
  2. इसके बाद Toast क्लास के object पर makeText() मेथड कॉल कीजिये और उसमे current application का context, text message और duration पास कीजिये।     
  3. इसके बाद toast object पर setGravitiy() मेथड कॉल करके toast मैसेज की position को सेट कीजिये।
  4. इसके बाद toast को show करने के लिए  toast object पर show() मेथड कॉल कीजिये।      



Example of Android Toasts 


Context appContext = getApplicationContext();
CharSequence msg = "Welcome to www.besthinditutorials.com";
int duration = Toast.LENGTH.SHORT;

Toast myToast = Toast.makeText(appContext, msg, duration);
myToast.setGravity(200,50,200);
myToast.show();


Comments

Popular posts from this blog

Android Services

Android Services Introduction to  android services in Hindi  Declaring  services in Hindi Creating a  android service in Hindi Introduction to Android Services इससे पहले की आप जाने की service क्या होती है आइये जानते है की service क्या नहीं होती है - एक service separate प्रोसेस नहीं होती है। ये आपकी एप्लीकेशन का ही पार्ट होती है।  एक service thread नहीं होती है।  आइये अब देखते है service क्या होती है - Service एक facility होती है जिससे आप android system को बता सकते है की आप कोई काम background में करते रहना चाहते है।  Service एक facility होती है जिससे एक एप्लीकेशन अपनी कुछ functionality दूसरी applications को expose कर सकती है।    हर service क्लास का <service> declaration AndroidManifest.xml file में होना चाहिए। Services को आप context.startService() और context.bindService() मेथड्स से स्टार्ट कर सकते है।            जब service component क्रिएट होता है तो android syst...

Android Activity

Android Activity Activity life cycle in Hindi Starting an  android activity in Hindi Creating a new activity in Hindi Destroying an  android activity in Hindi Introduction to Activity आप की application में एक से ज्यादा activity हो सकती है। जब आप इन activities के through navigate करते है, यानि एक activity से दूसरी activity में जाते है तो activity अपनी life cycle की different stages में जाती है। उदाहरण के लिए जब आपकी activity start होती है तो ये foreground में होती है और user का पूरा focus इस पर होता है। इस process के दौरान  android  system कुछ life cycle methods को call करता है। यदि user कोई दूसरी activity start करता है तो android system उस activity के life cycle methods को call करता है और आपकी पहले वाली activity background में चली जाती है। life cycle methods में आप decide कर सकते है की जब user जाता है या वापस आता है तो आपकी activity कैसे behave करेगी।  उदाहरण के लिए यदि आप एक वीडियो player बना रहे है तो जब user किसी दूसरी activity पर जाये तो...

Android Spinners

Android Spinners  Introduction to  android spinners in Hindi Defining  android spinners in Hindi Creating spinner items array in Hindi Responding to spinner selections in Hindi    Introduction to Android Spinners Android spinners आपकी एप्लीकेशन में एक drop down menu होती है। इस drop down menu में बहुत से items होते है जिन्हे user choices कहते है। जब user spinner पर क्लिक करता है तो ये items शो होते है। यूज़र अपने लिए appropriate choice choose करता है। By default spinner में सबसे top वाला element शो होता है। Spinners को XML layout file में क्रिएट किया जाता है। और items की लिस्ट string resource file में क्रिएट की जाती है। जिसमे आप एक string array क्रिएट करते है।  Spinner और items को जोड़ने के लिए एक array adapter क्रिएट किया जाता है। इसके बाद selection events को respond करने के लिए OnItemSelectedListener interface को  इम्प्लीमेंट किया जाता है।  Defining Android Spinners Android spinners को आप XML l...