Can't click on items in ListView with custom adapter

前端 未结 5 2198
梦谈多话
梦谈多话 2020-12-17 09:42

I am trying to write an application which takes items from a database and populates rows within a ListView. I can\'t click on the items after tapping on the rows and the dpa

相关标签:
5条回答
  • 2020-12-17 10:08

    Tried this?

            @Override
        public boolean isEnabled(int position) {
            //Set a Toast or Log over here to check.
            return true;
        }
    
    0 讨论(0)
  • 2020-12-17 10:18

    Add the line below to your ListView xml

    android:choiceMode="singleChoice"
    
    0 讨论(0)
  • 2020-12-17 10:20

    I usually put the click listener in the adapter itself:

    @Override
          public View getView(int position, View convertView, ViewGroup parent) {
    
            OnClickListener yourClickListener = new OnClickListener() {
                  public void onClick(View v) {
                    //put your desired action here
                    v.callOnClick();
                  }
              };
    
        ...
    
        // then add the listener to your view
        tweetView.setOnClickListener(yourClickListener);
    
    0 讨论(0)
  • 2020-12-17 10:26

    Usually this happens because the items in your listview are in focus. Try adding

    android:descendantFocusability="blocksDescendants"
    

    in your custom listview row

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip" 
        android:orientation="vertical"
        android:descendantFocusability="blocksDescendants">
    
    0 讨论(0)
  • 2020-12-17 10:29

    add inside onItemClick method:

    v.setSelected(true);
    
    0 讨论(0)
提交回复
热议问题