0

How can I customise this dialog? I'd like to set a Title, centre the text etc

I'd also like to know how to open an activity on item selection.

public void show (){
        ListView listView = new ListView(this);
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] {"Themes", "Advanced Launcher", "Help"}));
        Dialog dialog = new Dialog(this);
        dialog.setContentView(listView);
        dialog.show();

    }
user1353517
  • 300
  • 3
  • 10
  • 28

1 Answers1

0

Do it like this

public void show (){
        ListView listView = new ListView(this);
        listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new String[] {"Themes", "Advanced Launcher", "Help"}));
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // Do your stuff here.
            }
        });
        Dialog dialog = new Dialog(this);
        dialog.setTitle("Your Title");
        dialog.setContentView(listView);
        dialog.show();
    }

And for list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="item"
 android:layout_gravity="center_horizontal"/>

It will work.

Asad35Waheed
  • 121
  • 11