0

When I used a custom list array adapter for list view, the data are shown on the list but are not clickable. I already set a listener on a listview item click, but it's not working.

Also, I found another solution to make rows clickable and set background drawable on linear layout list view item layout but it's a bad trick to use this solution.

Is there any other solution for this?

Can any body tell me why does this happen? In list view which default functionality not working on custom array adapter

Here is my code:

public class Model {
    String name;
    String id;
    String price;
}

mArrayList = new ArrayList<Model>();
// mArrayList has some data in it 

mListiView.setsetAdapter(new myCoustomAdapter(mContext, mArrayList));
mListiView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(getBaseContext(), ""+position, Toast.LENGTH_LONG).show();
    }
});

public class myCoustomAdapter extends ArrayAdapter<Model> {
    ArrayList<Model> mList;

    public myCoustomAdapter(Context context, ArrayList<Model> list) {
        super(context, R.layout.item);
        this.mList=list;
    }

    @Override
    public int getCount() {
        return this.mList.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // layout data here 
        return view;
    }
}

Nothing happens on item click.

1
  • Post your custom adapter code, and the layout xml. Commented Aug 30, 2013 at 12:55

2 Answers 2

2

The first thing what you have to note here is, whenever there are Clickable elements like Buttons or ImageButtons present in your ListView element, they take the control of click events. And so your ListView won't get the chance to accept the click event.

What you simply have to do is, set the focusable attribute to false for the Button or ImageButton you have in your ListView. But still they will work without any problem and also your ListView's onListItemClick will also work.

Try this,

    <Button  android:id="@+id/textsize_increaser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/back_button"
    android:focusable="false"
    android:text=" A + "/>

Here I have added this android:focusable="false" and it works fine. try it.

Here is link for reference Click is not working on the Listitem Listview android

Sign up to request clarification or add additional context in comments.

Comments

0

Most likely your list view row's layout contains element that is clickable this it is "stealing" your clicks.

2 Comments

So what is your proposed solution for that issue
Review your row's layout. Ensure you got not clickable element there that can steal click. Fix the layout. Or change your adapter and assign onClickListener to either row view or certain view's elements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.