Wednesday, November 16, 2011

Hide showed Toast Messages

In my App, there is a list, when a user clicks on an button, a toast message is being displayed, 10 items - 10 toast messages, so if the user clicks 10 times, then presses the button... he/she has to wait for some seconds, until he's able to read the menu option text.

I have found the below solution to hide the shows toast message.

public class SampleToastActivity extends Activity {
Toast myToast;
static int i=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b1 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i++;
if(myToast!=null){
myToast.cancel();
myToast.setText("Count"+i);
}else{
myToast = Toast.makeText(SampleToastActivity.this, "Sample"+i, 10);
}
myToast.show();
}
});
}
}

10 comments:

  1. Its great if it will really work. There are too many android applications provided by android app developers so that android mobile phones perform awesome.

    ReplyDelete
  2. Thanks for this information this was really helpful.
    Best Android Apps

    ReplyDelete
  3. your blog is nice,if you upload any screen shots then it's use full to all of us...thanks

    ReplyDelete
  4. Good to know about your blog i have visit and i am very inspired from your ideas It will be interesting to see what we learn about the use of mobile phones in the coming years.

    Big Button Mobile Phones

    ReplyDelete
  5. It's nice information that advice me how to hide showed toast messages in the android smart phone so i say thanks for posting this kind of blog which help me and other user who don't know this kind of facility of android.


    Android App Development

    ReplyDelete
  6. Thanks for share this nice post. Very helpful.

    Android Apps

    ReplyDelete
  7. Excellent article. Thanks for this kind of article.
    Top Url Shortener Sites

    ReplyDelete
  8. Recently i am facing this issue, by reading your article now i am able to resolve this bug in my program. Thank for sharing it with us!!!

    apps developers India

    ReplyDelete
  9. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    Mobile App Development

    ReplyDelete