Android - Custom Lists

560 Views Asked by At

I am not sure about how do we custom lists is android 2.2 or any later

I want a basic activity that can make custom lists by layout inflater

any help would be appreciated!

1

There are 1 best solutions below

1
On

I'm not sure if this is what you want, so, here an example on how to show a list dialog:

/* create the dialog */
final AlertDialog.Builder dlg = new AlertDialog.Builder(this);

/* create the list of items to show on listbox */
String [] myList = {"A","B","C","D","E"};

/* create an adapter to control how the listbox should appear */
final ArrayAdapter<String> adapter = new ArrayAdapter<String>
  (this,android.R.layout.select_dialog_singlechoice,myList);

/* the item that will be initially selected on listbox */
int selected = 0;

/* inform the dialog about our items and create an onClick function to listen for
   user inputs */
dlg.setSingleChoiceItems(adapter,selected,
  new  DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
      // selected item is myList[which];
      dialog.dismiss();
    }
  });

/* change the dialog title */
dlg.setTitle("My dialog");

/* show the dialog */
dlg.show();

This will show a dialog with radio buttons for the user to select one of them. When the user perform a click on the item, the onClick funcion will be called. The selected item is pointed by the 'which' argument. The 'dlg' object offers other ways to show the list of items, allowing you to show items without the radio button, create some buttons on the dialog and things like this. Just play with object's methods to see the differences.