Reputation: 24012
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?
Upvotes: 1
Views: 1592
Reputation: 15701
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
Upvotes: 1
Reputation: 2071
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
}
});
}
Upvotes: 2
Reputation: 2624
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);
Upvotes: 1
Reputation: 67286
Yes you can do that inside the Adapter class itself. Just set the click listeners for ImageView and Textview in the Adapter class.
Upvotes: 3