Ok so i’ve written my main xml file and i’m pretty sure its correct, but I dont know how to display my layout on the screen. I tried creating variables for all the different widgets and setting them to the same as in the R.id.main but it didnt show anything on screen. basically i don’t understand how to display what ive got in xml on screen. This is my code, please can someone explain where i’m going wrong.
public class MinesweeperActivity extends Activity {
private TableLayout all;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
all = (TableLayout)findViewById(R.id.all);
}
}
// this is my xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/all"
android:stretchColumns="*"
android:background="@drawable/bground"
>
<TableRow>
<TextView
android:id="@+id/Timer"
android:layout_column="0"
android:text="000" />
<TextView
android:id="@+id/Counter"
android:layout_column="2"
android:text="000" />
<ImageButton
android:id="@+id/Face"
android:layout_column="1"
android:background="@drawable/faces"
android:layout_height="50px" />
</TableRow>
<TableRow>
<TextView
android:layout_column="0"
android:layout_height="50px"
android:layout_span="3"
android:padding="10dip"/>
</TableRow>
<TableRow>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Mines"
android:layout_width="260px"
android:layout_height="260px"
android:gravity="bottom"
android:stretchColumns="*"
android:layout_span="3"
android:padding="5dip" >
</TableLayout>
</TableRow>
</TableLayout>
I tried with your code and i found the error in logcat is
**java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.**I think the mistake is this..Try once it may solve your problem.You must give layout widh and height attributes to the table layout.