1

I have a Custom ListView which has an ImageView and a TextView. and i implemented ListView.setOnItemSelectedListener();

But is these a way to make both the ImageView and TextView Clickable (Separately), I mean Click on ImageView must call ActivityA and Click on TextView must call ActivityB?

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226

4 Answers4

3

Yes you can do that inside the Adapter class itself. Just set the click listeners for ImageView and Textview in the Adapter class.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
2

Yes ofcourse!

In your custom ListAdapter, you can set onClickListener like below:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if( row == null ){
        LayoutInflater vi = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = vi.inflate(this.textViewResourceId, null);
    }

    row.findViewById(R.id.image_item).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });

    row.findViewById(R.id.text_item).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });     
}
Veer
  • 2,071
  • 19
  • 24
1

there are lots of example for the same

like this

point should keep

  • You need set the listener to each view in getView (don't create in each time in get view just pass already created one or can pass this and implement the listener in same adapter class)

  • make the view (like TextView ) clickable true

  • You 'll also required the row position so can use different logic like get & Set tag or at view parant as in this link

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
1

Yes ofcourse you can achieve that. You can set onClickListener on them separately inside the adapter class and then set these buttons or textviews as not focusable if you want a different action to be done on clicking the whole list item, using onItemClickListener.

        yourButton.setFocusable(false);
        yourButton.setFocusableInTouchMode(false);
Yogesh Somani
  • 2,624
  • 3
  • 21
  • 34