I made my own customized ListView and in each row there are 2 TextViews.
I intend to make those textviews 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);
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;
}
set your TextView in your layot.xml
<TextView
android:id="@+id/YourID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
/>
and then on your Custom Adapter
@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.youLayout, null);
holder.txt1 = (TextView) row.findViewById(R.id.tx1);
holder.txt2 = (TextView) row.findViewById(R.id.tx2);
holder.txt1 .setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//your statements
}
});
holder.txt2 .setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//your statements
}
});
}
return row;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With