Clickable TextView inside a customized ListView
android, android-listview, textview
Solution
In your Adapter class, inside getview() method you can perform onclick action like this
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
Holder holder = null;
if (row == null) {
LayoutInflater vi =
(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = vi.inflate(R.layout.listitem, null);
holder.txtTitle1 = (TextView) row.findViewById(R.id.heading1);
holder.txtTitle2 = (TextView) row.findViewById(R.id.heading2);
holder.txtTitle1 .setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
holder.txtTitle2 .setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
}
return row;
}
/////
///////////
static class Holder {
TextView txtTitle1;
TextView txtTitle2;
}
Problem
I made my own customized `ListView` and in each row there are 2 `TextView`s. I intend to make those `textview`s inside each row of the `listview` clickable. So whenever the user clicks on any of them, it will redirect him to some other place. Actually, when the user clicks on a `ListView` item, it clicks all of it, and the `textviews` are being ignored. In conclusion, when I click on a `ListView` item, I don't want the Listview item to respond, I want the `Textview` inside the `Listview` to respond. EDIT: Here is how i customized my view: ``` String[] from = {"value1", "value2"}; int[] to = {R.id.label, R.id.label2}; SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, data, R.layout.rowlayout, from, to); ```