Need Help in Firing TableRow Event in Android?
Hai Friends, I want to invoke or fire the onclick event for Table Row when the user clicked a particular table row in the UI. This is my xml code
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table_bars" android:layout_width="wrap_content" android:layout_height="fill_parent"android:background="@drawable/corner" android:stretchColumns="1" android:layout_margin="10dp">
<TableRow>
<TextView android:id="@+id/barsp_baradd_value"
android:textSize="15sp" android:padding="10dp" android:layout_width="wrap_content" />
</TableRow>
<View android:layout_height="1dp" android:background="#FF909090" />
<TableRow>
<TextView android:id="@+id/barsp_barphone_value"
android:textSize="15sp" android:padding="10dp" android:layout_width="wrap_content" />
<ImageView android:id="@+id/san_arrow2" android:src="@drawable/newforward" android:layout_alignParentRight="true"
android:adjustViewBounds="true" android:layout_marginTop="10dp"
android:layout_width="30dp" android:layout_height="35dp" android:paddingRight="4dp" />
</TableRow>
<View android:layout_height="1dp" android:background="#FF909090" />
<TableRow android:id="@+id/barsite">
<TextView android:id="@+id/barsp_barsite_value"
android:textSize="15sp" android:padding="10dp" android:layout_width="wrap_content" />
<ImageView android:id="@+id/san_arrow3" android:src="@drawable/newforward" android:layout_alignParentRight="true"
android:adjustViewBounds="true" android:layout_marginTop="10dp"
android:layout_width="30dp" android:layout_height="35dp" android:paddingRight="4dp" />
</TableRow>
</TableLayout>
and my Java code is
TableRow row = (TableRow)findViewById(R.id.row1);
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
//Log.v(TAG, "try");
uri = Uri.parse("geo:0,0?q=" + VALUE_baraddress1[0] + ", "
+ VALUE_baraddress2[0] + ", "
+ VALUE_baraddress3[0]);
//Log.v(TAG, VALUE_baraddress1[0] + ", "
// + VALUE_baraddress2[0] + ", "
// + VALUE_baraddress3[0]);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} catch (Exception e) {
//Log.v(TAG, "catch");
uri = Uri.parse("geo:0,0?q=" + VALUE_baraddress1[0] + ", "
+ VALUE_baraddress3[0]);
//Log.v(TAG, VALUE_baraddress1[0] + ", "
// + VALUE_baraddress3[0]);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
}
});
i had got null pointer exception in this line
TableRow row = (TableRow)table.getChildAt(0);
Logcat Messages
11-10 15:47:04.164: ERROR/AndroidRuntime(12720): ... 11 more
11-10 15:47:04.164: ERROR/AndroidRuntime(12720): Caused by: java.lang.NullPointerException
11-10 15:47:04.164: ERROR/AndroidRuntime(12720): at com.fsp.blacksheep.BS_Bars.onCreate(BS_Bars.java:546)
11-10 15:47:04.164: ERROR/AndroidRuntime(12720): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
11-10 15:47:04.164: ERROR/AndroidRuntime(12720): at android.app.A开发者_开发问答ctivityThread.performLaunchActivity(ActivityThread.java:2364)
11-10 15:47:04.164: ERROR/AndroidRuntime(12720): ... 19 more
11-10 15:47:06.324: ERROR/JavaBinder(972): !!! FAILED BINDER TRANSACTION !!!
I'm not quite sure if that even works but you should set the android:clickable
attribute to true
if you are planing to have the TableRows
clickable. I haven't tried it tho.
精彩评论