Default Selection of a Row in the ListView and HighLight the selected Row Android

前端 未结 3 1449
慢半拍i
慢半拍i 2020-12-21 07:42

I have 2 listview. I want when the activity starts first row of the both the listview to be selected by default.I googled up i found this

onewaydata=new One         


        
3条回答
  •  無奈伤痛
    2020-12-21 07:56

    **THIS WORKS FOR ME.You have to make custom adapter.**
    
         First Create Modal Class
    
            public class FilterBean {
    
             String filter_catagory;
                     boolean isSelected;
    
                public boolean isSelected() {
                    return isSelected;
                }
    
                public void setSelected(boolean selected) {
                    isSelected = selected;
                }
    
              public String getFilter_catagory() {
                    return filter_catagory;
                }
    
                public void setFilter_catagory(String filter_catagory) {
                    this.filter_catagory = filter_catagory;
                }
    
            }
    
    
        In Adapter Class
    
        @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                convertView = layoutInflater.inflate(R.layout.size_name_indicator, null);
                txt = (TextView) convertView.findViewById(R.id.key_textView);
                txt.setText(getItem(position).getFilter_catagory());
    
                if(getItem(position).isSelected()){
                    txt.setBackgroundColor(context.getResources().getColor(R.color.transparent));
                }else {
    
                    txt.setBackgroundColor(context.getResources().getColor(R.color.colorWhite));
                }
    
    
                return convertView;
            }
    
         public void updateNameBean(String key,boolean checked)
            {
    
                for(int i=0;i adapterView, View view, int position, long id) {
                    String key = filterNameAdapter.getItem(position).getFilter_catagory();
                    filterNameAdapter.updateNameBean(filterNameAdapter.getItem(position).getFilter_catagory(),true);
    
                }
            }); 
    

提交回复
热议问题