Android listview item click is not working

前端 未结 3 1907
逝去的感伤
逝去的感伤 2020-12-10 10:06

I have seen similar questions and tried the solutions such as setting focusable to false but it is still not working. Here is my layout that contains the listview:



        
相关标签:
3条回答
  • 2020-12-10 10:20

    after setting

    android:focusable="false"

    for your ListView content, in your ListView Tag Add

    android:clickable="true"

    0 讨论(0)
  • 2020-12-10 10:24

    Actually nothing is wrong.

    But the problem is from the custom_list_row.xml, when you click on the list view item,

    You actually click on other tags in your custom_list_row.xml

    and these tags are not responsible for firing the ItemClickListener.

    Change value of property android:layout_width of tags in the custom_list_row.xml to "wrap_content" or remove the tags and try again.

    0 讨论(0)
  • 2020-12-10 10:25

    I too faced this issue, I overcome from this issue by setting click listener to convertView of custom adapter. I don't know is this good approach but it solved my issue.

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        KeepassDBGroupv1 rowItem = getItem(position);
    
        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.custom_list_row, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.textView_group_entry_name);
            holder.imageView = (ImageView) convertView.findViewById(R.id.imgView_group_entry_icon);
            holder.type = (TextView) convertView.findViewById(R.id.textView_group_entry_type);
            convertView.setTag(holder);
        } else 
            holder = (ViewHolder) convertView.getTag();
    
        holder.name.setText(rowItem.getGroupName());
        holder.type.setText("Group");
        Drawable d = context.getResources().getDrawable(context.getResources().getIdentifier("ic"+Integer.toString(rowItem.getImageId()), "drawable", context.getPackageName()));
        holder.imageView.setImageDrawable(d);
        //App.getDB().drawFactory.assignDrawableTo(holder.imageView, context.getResources(), rowItem.icon);
        convertView.setOnClickListener(new OnClickListener(){
              @Override
              public void onClick(View v) {
                  Log.v("OpenDbListAdapter ","List View Clicked");
              }
        });
        return convertView;
    }
    
    0 讨论(0)
提交回复
热议问题