Hi im trying to get the ID i set on each of these linear layouts but instead im getting
android.widget.LinearLayout@41032a40 or similar which isn't much use to me.
I have set the id to row1, and thats what i would like to return.
Im sure I've done something similar before, so i cant figure out why it is returning the above.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/row1"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@android:color/black"
android:onClick="xmlClickHandler" />
<LinearLayout
android:id="@+id/row2"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@android:color/white"
android:onClick="xmlClickHandler" />
<LinearLayout
android:id="@+id/row3"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@android:color/black"
android:onClick="xmlClickHandler" />
<LinearLayout
android:id="@+id/row4"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@color/white"
android:onClick="xmlClickHandler" />
<LinearLayout
android:id="@+id/row5"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@color/yellow"
android:onClick="xmlClickHandler" />
<LinearLayout
android:id="@+id/row6"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@color/blue"
android:onClick="xmlClickHandler" />
public void xmlClickHandler(View v) {
Log.d("CLICK ROW", String.valueOf(v));
}
View ID can be checked using v.getID()
You can simply check as
if(v.getId()==R.id.row1)
and perform your desired task accordingly.
You can do it in this way:
public void xmlClickHandler(View v) {
String viewID = getResources().getResourceName(v.getId());
}
And than you have to parse the result string.
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