Get clicked item: Android
android, click
Solution
add android:clickable in TexView Layout for making TextView Clickable :
android:clickable="true"
and in Code Part:
TextView text = new TextView(this);
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
text.setText("YOUR TEXT");
text.setId(5111);
text.setClickable(true);
text.setOnClickListener(handler);
View.OnClickListener handler =new View.OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.mytextviewone: // doStuff
break;
case R.id.mytextviewone: // doStuff
break;
}
}
}
Problem
I have a dynamically inflated layout. ``` <TableLayout> <!-- Two more tablelayout here --> <ScrollView> <TableLayout> <!-- Here a tablerow is added using inflate layout --> <TableLayout> </ScrollView> </TableLayout> ``` The layout for the table row looks like this. ``` <?xml version="1.0" encoding="utf-8"?> <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" style="@style/savedItemRow"> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TextView style="@style/textviewSaved" android:id="@+id/text_item"/> <TextView android:id="@+id/text_item_responce" style="@style/textviewSavedSub" /> </TableLayout> </TableRow> ``` I would like listen when the text_item id is clicked (Keeping in mind that I have dynamically created tablerows created at run time). I am an android noob. I am not sure if I asked the question the right way. I want to get the click item's properties somehow during run time so I can manipulate them. Thank you.