I m trying to add an image into the existing table row in the xml layout. But something is wrong, having NullPointerException. Can u pls tell me the way to add any view to the existing row in the xml. thnx
TableLayout tbl= (TableLayout)findViewById(R.id.tableLayout1);
TableRow row= (TableRow)findViewById(R.id.tblHips);
ImageView image=(ImageView) findViewById(R.drawable.ic_launcher);
//image.setImageResource()
row.addView(image);
tbl.addView(row);
This my layout-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|center" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView02"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Waist"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/EditText02"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="@+id/tblHips"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />
</TableRow>
</TableLayout>
</RelativeLayout>
To make it simple I have deleted some other rows with the same type of views.
try this