Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello friends, I am a new to Android development. I want to show a Listbutton dialog box with multichoiceitems options in android. for that I have used the below code.

I am calling this dialog box on button click event.
I am able to see the title and message I set for that dialog box, and button also is visible but I am unable to get the list of colors that I am setting to the dialog.

here is my code

btn=(Button) findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
final ArrayList<String> selColors=new ArrayList<String>();	
try
{
		AlertDialog.Builder dialog1=new AlertDialog.Builder(getApplicationContext());
		final String[] Colors={"Red","Green","Blue","Orange","Pink"};
		final boolean[] _selections = {true,true,true,true,true,true,true};
		dialog1.setTitle("Colors List");
		dialog1.setMessage("Select Your Favoriate Color");
		dialog1.setMultiChoiceItems(Colors, _selections, new DialogInterface.OnMultiChoiceClickListener()
	{	
	@Override
	public void onClick(DialogInterface dialog, int which, boolean isChecked)
	{
	if(isChecked)
	{
	selColors.add(Colors [which]);
	Toast.makeText(getApplicationContext(),"You have selected " + Colors [which],Toast.LENGTH_SHORT).show();
	}
	}
	});
	dialog1.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
	@Override
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getApplicationContext(),"SAVED",Toast.LENGTH_SHORT).show();
}
});
dialog1.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getApplicationContext(),"CANCELED",Toast.LENGTH_SHORT).show();
}
});
}
catch(Exception ex)
{
TextView tv=(TextView) findViewById(R.id.textView1);
tv.setText(ex.toString());
Toast.makeText(getApplicationContext(),ex.toString(),Toast.LENGTH_LONG).show();
}
}
});



Please provide me what may be the wrong. Why I am unable to call the event I mean nothing is happening when I click the button.

Thanks
Ganesh
Posted
Updated 12-Jan-13 2:21am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900