in Education by
I have been searching about ListDialogs . Whenever you can put the item you want with the : builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { } }); And thinking about the the items object, which is a CharSequence like this: CharSequence[] items = getResources().getStringArray(R.array.share_dialog_list); I want to know if there is a way (someone other must have made it) to make this exist, but using a custom view with icons to the left, like this: JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Here is a complete solution with an extended ArrayAdapter that allows icons. See design notes for dialogs at http://developer.android.com/design/building-blocks/dialogs.html Iconogaphy at http://developer.android.com/design/style/iconography.html and IconPacks at http://developer.android.com/design/downloads/index.html Note that the size for these looks pretty good at 48 x 48 dp, which isn't a bundled size, so you'll have to scale your own icon from the downloads. USAGE: @Override public void onClick(View v) { final String [] items = new String[] {"From Gallery", "From Camera"}; final Integer[] icons = new Integer[] {R.drawable.dialog_gallery_icon, R.drawable.dialog_camera_icon}; ListAdapter adapter = new ArrayAdapterWithIcon(getActivity(), items, icons); new AlertDialog.Builder(getActivity()).setTitle("Select Image") .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item ) { Toast.makeText(getActivity(), "Item Selected: " + item, Toast.LENGTH_SHORT).show(); } }).show(); } ArrayAdapterWithIcon.java public class ArrayAdapterWithIcon extends ArrayAdapter { private List images; public ArrayAdapterWithIcon(Context context, List items, List images) { super(context, android.R.layout.select_dialog_item, items); this.images = images; } public ArrayAdapterWithIcon(Context context, String[] items, Integer[] images) { super(context, android.R.layout.select_dialog_item, items); this.images = Arrays.asList(images); } public ArrayAdapterWithIcon(Context context, int items, int images) { super(context, android.R.layout.select_dialog_item, context.getResources().getTextArray(items)); final TypedArray imgs = context.getResources().obtainTypedArray(images); this.images = new ArrayList() {{ for (int i = 0; i < imgs.length(); i++) {add(imgs.getResourceId(i, -1));} }}; // recycle the array imgs.recycle(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); TextView textView = (TextView) view.findViewById(android.R.id.text1); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelativeWithIntrinsicBounds(images.get(position), 0, 0, 0); } else { textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0); } textView.setCompoundDrawablePadding( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getContext().getResources().getDisplayMetrics())); return view; } }

Related questions

0 votes
    I have been searching about ListDialogs . Whenever you can put the item you want with the : builder. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    I am using DPro Rio 10.3 on an HP Spectre x360, which has a 4K display. The indicator on DbGrids ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    As we all know IOS 5 is gonna bring us emoji keyboard for everyone. My question is if there is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    As we all know IOS 5 is gonna bring us emoji keyboard for everyone. My question is if there is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    Have jquery dialog as closeOnescape as false. want to trigger an event based on esc key press how do ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Could anybody give any piece of advice, or code, or documentation link where I can found: how to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I need to build a pop up dialog box in my app. I am using Dialog class and wrapped it with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    (This is a random image of showing a Dialog found on the Internet.) I've been implementing a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I am trying to do some validation on the file name before it's saved. Here are my three file- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I'm used to v3 node botbuilder sdk so I have a middleware where I look at the dialog stack and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    In VB.NET is there a library of template dialogs I can use? It's easy to create a custom dialog ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    In VB.NET is there a library of template dialogs I can use? It's easy to create a custom dialog ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
...