Multiple choice list with custom view?

后端 未结 9 797
失恋的感觉
失恋的感觉 2020-12-02 09:07

I\'ve seen example com.example.android.apis.view.List11 from ApiDemos. In that example, each row takes the view android.R.simple_list_item_multiple_

9条回答
  •  孤街浪徒
    2020-12-02 09:16

    It is possible by some trick

    in your ListActivtyClass in method

    protected void onListItemClick(ListView l, View v, int position, long id) {
    //just set
    .setSelected(true);
    }
    

    now in you custom Adapter

    public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(textViewResourceId, parent, false);
            }       
            if (.isSelected()) {
                convertView.setBackgroundColor(Color.BLUE);
            } else {
                convertView.setBackgroundColor(Color.BLACK);
            }
            return convertView;
        }
    

    this way you can customize the view in adapter when the item is selected in the list.

提交回复
热议问题