Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Toast with AlertDialog in android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 354
    Comment on it

    Here I have created Toast with alertDialog code function, according to below code both function runs in same time and display same time when we clicked listview item. In the below code I have explain how to make toast with AlertDialog function in android.

    lvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
                    ListData mLog = listAdapter.getItem(position);
    
                    Toast.makeText(MainActivity.this, "Title:" + mLog.getTitle() + " Description:" + mLog.getDescription(), Toast.LENGTH_LONG).show();
                    Toast.makeText(MainActivity.this, "Title: " + mLog.getTitle() + "  Description: " + mLog.getDescription(), Toast.LENGTH_LONG).show();
                    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                    alertDialog.setTitle("Remove this Item ?");
                    alertDialog.setMessage("Are you sure you want to remove this ListItem? ");
                    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog.setButton2("Remove", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            myList.remove(position);
                            listAdapter.notifyDataSetChanged();
                            listAdapter.notifyDataSetChanged();
    
                            Toast.makeText(getApplicationContext(), "Removed from list", Toast.LENGTH_SHORT).show();
                        }
                    });
    
                    alertDialog.show();
                }
            });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: