Customize dialog which has single-choice list items

后端 未结 3 824
一整个雨季
一整个雨季 2021-02-05 23:55

I created a Dialog with single-choice list items:

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

AlertDialog.Builder builder = ne         


        
3条回答
  •  -上瘾入骨i
    2021-02-06 00:26

    You basically will have to create your own ListAdapter by subclassing one of the available Adapter classes and supply that to the dialog (using builder.setAdapter(...)). If you have an array or list of items/objects, subclassing ArrayAdapter is probably what you'll want to look into.

    In your Adapter subclass, you override the getView(...) method (amongst others) and fill the views of your custom layout with data for the supplied position in the list. More specifically, you'll want to set an image against an ImageView and text to a TextView.

    A fairly nice tutorial that demonstrates how to implement a custom ArrayAdapter, and happens to be close to what you're trying to accomplish, can be found here. It also shows how to use the ViewHolder/RowWrapper concept.

提交回复
热议问题