Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:09:24+00:00 2026-05-31T18:09:24+00:00

I created a Dialog with single-choice list items: final CharSequence[] items = {Red, Green,

  • 0

I created a Dialog with single-choice list items:

final CharSequence[] items = {"Red", "Green", "Blue"};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Colors");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
                Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
            }
        });
AlertDialog alert = builder.create();
alert.show();

How can I customize the layout of this dialog so that each list item in the dialog consists of a icon and a text. How to create custom layout for the list on the dialog?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:09:25+00:00Added an answer on May 31, 2026 at 6:09 pm

    Steps for Creating customize dialog:

    1. Create the dialog box layout files, like:

      <RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
      android:layout_width = "wrap_content"
      android:layout_height = "wrap_content">
      <!-- The Title Bar -->
      <LinearLayout
          android:id="@+id/dlg_priority_titlebar"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true">
      
          <ImageView
              android:src="@drawable/image"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="5dip" />
      
          <TextView
              android:layout_width = "wrap_content"
                  android:layout_height = "wrap_content"
                  android:text = "Select Task Priority"
                  android:layout_gravity = "center_vertical" />
      </LinearLayout>
      <ListView 
          android:id="@+id/dlg_priority_lvw"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/dlg_priority_titlebar"
          android:background="@drawable/layout_home_bg">
      </ListView>
      

    2. Because the layout in the ListView custom, so to create a layout file for the ListView:

      <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 
          android:orientation = "horizontal" 
          android:layout_width = "fill_parent" 
          android:layout_height = "fill_parent"> 
      
      <ImageView 
            android:id = "@+id/list_priority_img" 
            android:layout_width = "wrap_content" 
            android:layout_height = "wrap_content" 
            android:layout_gravity = "center_vertical" 
            android:layout_margin = "5dip" /> 
      <TextView 
           android:id = "@+id/list_priority_value" 
           android:layout_width = "wrap_content" 
           android:layout_height = "wrap_content" 
           android:layout_gravity = "center_vertical" 
           android:textsize = "28dip" 
           android:textColor = "@drawable/ black" /> 
      </LinearLayout>
      
    3. Create a custom Dialog class PriorityDlg inherited from Dialog

           public class PriorityDlg extends Dialog {
      
          private Context context;
          private ListView dlg_priority_lvw = null;
          public PriorityDlg(Context context) {
              super(context);
              this.context = context;
              // TODO Auto-generated constructor stub
          }
          public PriorityDlg(Context context, int theme) {
              super(context, theme);
              this.context = context;
          }
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              // TODO Auto-generated method stub
              super.onCreate(savedInstanceState);
              this.setContentView(R.layout.dlg_priority);
              dlg_priority_lvw = (ListView) findViewById(R.id.dlg_priority_lvw);
              // ListView
              SimpleAdapter adapter = new SimpleAdapter(context, getPriorityList(),
                      R.layout.lvw_priority, new String[] { "list_priority_img",
                              "list_priority_value" }, new int[] {
                              R.id.list_priority_img, R.id.list_priority_value });
              dlg_priority_lvw.setAdapter(adapter);
              //ListView
              dlg_priority_lvw
                      .setOnItemClickListener(new AdapterView.OnItemClickListener() {
      
                          @Override
                          public void onItemClick(AdapterView<?> arg0, View arg1,
                                  int arg2, long arg3) {
      
                          }
                      });
          }
          private List<HashMap<String, Object>> getPriorityList() {
              List<HashMap<String, Object>> priorityList = new ArrayList<HashMap<String, Object>>();
              HashMap<String, Object> map1 = new HashMap<String, Object>();
              map1.put("list_priority_img", R.drawable.priority_not_important);
              map1.put("list_priority_value", context.getResources().getString(
                      R.string.dlg_priority_not_important));
              priorityList.add(map1);
              HashMap<String, Object> map2 = new HashMap<String, Object>();
              map2.put("list_priority_img", R.drawable.priority_general);
              map2.put("list_priority_value", context.getResources().getString(
                      R.string.dlg_priority_general));
              priorityList.add(map2);
              HashMap<String, Object> map3 = new HashMap<String, Object>();
              map3.put("list_priority_img", R.drawable.priority_important);
              map3.put("list_priority_value", context.getResources().getString(
                      R.string.dlg_priority_important));
              priorityList.add(map3);
              HashMap<String, Object> map4 = new HashMap<String, Object>();
              map4.put("list_priority_img", R.drawable.priority_very_important);
              map4.put("list_priority_value", context.getResources().getString(
                      R.string.dlg_priority_very_important));
              priorityList.add(map4);
      
              return priorityList;
          }
      
      }
      
    4. To create a custom dialog box

      PriorityDlg dlg = new PriorityDlg (SimpleTaskActivity.this, R.style.dlg_priority); 
      dlg.show();
      

    Where R.style.dlg_priority set the dialog box uses the style file, just let the dialog box to remove the title bar, and of course you can code to complete this effect:

    <? Xml version = "1.0" encoding = "utf-8"?> 
    <resources> 
        <style name="dlg_priority" parent="@android:Theme.Dialog"> 
            <item name = "android: windowNoTitle"> true </ item> 
        </ style> 
    </ resources>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an Alert Dialog with a list of single-choice items
This is happening on Vista. I created a new dialog based MFC project to
I have an alert dialog with a single-choice list and two buttons: an OK
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I would like to create a single-choice dialog form ( similar to what you
I created a new Telerik reporting class library (single report for now) which builds
I haven't been able to set a Single Choice list, or a Multiple Choice
We have two AlertDialog objects AlertDialog dialog1, dialog2; both dialogs are created via AlertDialog.Builder
I created a dialog with a jpanel inside it, and that jpanel will be
I have created a Dialog with two buttons Yes, No, and then I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.