I simply want to know how to call/attach/send a table with text to a button. I can get ListView to work fine but I don’t know the “idea” behind a TableLayout. All I want it to do is: when the button is pressed it should go to the table and display the text. I’m not looking for anything fancy just simply display the text in a table when the button is pressed. I have a button (named buttonInfo.java)set up on a menu like this:
Button btnInfo = (Button) findViewById(R.id.buttonInfo);
btnInfo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.crazyj.peopleinfo.BUTTONINFO"));
}
});
Here is the table (named infotable.xml)with the text:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView android:text="Name"
android:padding="3dip" />
<TextView android:text="John"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView android:text="Number"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView android:text="Age"
android:padding="3dip" />
<TextView android:text="32"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
buttonInfo class:
package com.crazyj.peopleinfo;
import android.content.Context;
import android.widget.TableLayout;
public class buttonInfo extends TableLayout{
public buttonInfo(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}
If anyone can answer this please explain what it means! I’m here to learn, not just get answers. And thanks!
This tutorial section better illustrates what you are trying to achieve. Treat the tabs like buttons just to get the concept. It will show you how to create activity classes and invoke them using onClick
(look around step 6)
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
so when you call the activity BUTTONINFO, you have to keep in mind that BUTTONINFO doesn’t exactly hold the TableLayout. So BUTTONINFO would be extending activity, since it implements an activity.
Inside your public class for BUTTONINFO you would need
this tells the activity that it needs to set this as the view. “R.layout.infotable” being where it is. (when you made the xml file, there is an android file r that updates itself to include the xml file. so infotable.xml is being called as the view.