0

i want to create a dialog which when popup will show items. but the problem is that when i am popping my dialog it is showing only the title and a blank space i am not getting my items in my dialog.here is my code:

@Override
public void onClick(View v) {

  final String list[]={"r","g","b"};

  AlertDialog.Builder alert = new AlertDialog.Builder(myAct.this);

  alert.setTitle("dialog with list");

  alert.setItems(list,new DialogInterface.OnClickListener(){
    @Override
    public void onClick(DialogInterface dialog,int which) {
      Toast.makeText(getApplicationContext(),""+list[which],1000).show()
    }
  });
  alert.show();
Josnidhin
  • 12,469
  • 9
  • 42
  • 61
sachit
  • 1,128
  • 2
  • 12
  • 25

2 Answers2

1

http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Did you refer to this?

If so, can you try this

final String[] list={"r","g","b"};

instead of

final String list[]={"r","g","b"};
gaara87
  • 2,087
  • 3
  • 21
  • 43
  • 1
    then why dont you create a listview inside the dialog and populate it? Do you necessarily only want to use the default capability? – gaara87 Aug 07 '12 at 09:43
  • yes i have done with that and its working for me but why the default method setItems() is not working.. – sachit Aug 07 '12 at 10:05
0

Try after adding items in CharSequence[]. Refer this doc for more details.

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
  • yes i am also using the same thing but unfortunately items is being not added in my dialog.it is showing dialog only with title and some blank space. – sachit Aug 07 '12 at 07:01
  • Please go thru the doc. It will definitely solve your problem. Use alert.create() instead of alert.show(); – Vineet Shukla Aug 07 '12 at 07:07
  • i have read the docs and also following. but every time i am getting the same output.and alert.create() will create the dialog but for showing the dialog i have to call show() method. – sachit Aug 07 '12 at 07:41