自定义AlertDialog 问自己的单选item

1.主要dialog.setAdapter 

public static void showContextMenu(Context context, String title, BaseAdapter adapter, final DialogInterface.OnClickListener itemclickListener) {
        Builder dialog = new AlertDialog.Builder(context);
        dialog.setTitle(title);
        dialog.setAdapter(adapter, new OnClickListener()
        {
            
            @Override
            public void onClick(DialogInterface dialog, int which) {
                itemclickListener.onClick(dialog, which);
            }
        });
        dialog.show();
    }




public class ChooseGroupAdapter extends KKBaseAdapter<Group>
{
    
    public ChooseGroupAdapter(Context context) {
        super(context);
    }
    
    @Override
    public int onGetItemLayout() {
        return R.layout.layout_list_item;
    }
    
    @Override
    public void onGetView(final View convertView, final int position) {
        Group p = mDataList.get(position);
        TextView item_title = findViewById(convertView, R.id.item_title);
        item_title.setText(p.getName());
    }
    
}

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_title"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="center" />



2.自定义ArrayAdapter 使用自己的布局和自己的数据

final ArrayAdapter<products> chooseProductAdapter = new ArrayAdapter<products>(this, R.layout.layout_list_item, baseBean.getChooseProduct())
                {
                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                        if (convertView == null) {
                            convertView = ViewUtil.inflateView(R.layout.layout_list_item, parent);
                        }
                        
                        final TextView text1 = (TextView) convertView.findViewById(R.id.item_title);
                        final String display = this.getItem(position).getName();
                        text1.setText(display);
                        
                        return convertView;
                    }
                };





你可能感兴趣的:(自定义AlertDialog 问自己的单选item)