how to align the content to its column title, i have here the sample below
Name-----------------Number-----------------Age
Yan 1232312 25
here is my xml code to view the sqlite database
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:text="Name" >
</TextView>
<TextView
android:id="@+id/Hot"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:text="Number" >
</TextView>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/tvSqlInfo"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:text="Name" >
</TextView>
/>
</LinearLayout>
and this one is the my Activityclass to view the xml,can you please teach me where to put the tablelayout parameter thanks
`public class SQLView extends Activity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sqlview);
TableLayout table = (TableLayout) findViewById(R.id.table);
TableRow row= new TableRow(this);
TextView text = new TextView(this);
row.addView(text);
table.addView(row);
TableLayout.LayoutParams l =
new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
l.weight = 1;
tv= (TextView)findViewById(R.id.tvSqlInfo);
HotorNot info = new HotorNot(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
here is my database class
public class HotorNot {
public static final String KEY_ROWID= "_id";
public static final String KEY_NAME= "Person_Names";
public static final String KEY_HOT= "personHOT";
private static final String DATABASE_name= "HotorNotdb";
private static final String DATABASE_TABLE= "PeopleTable";
private static final int DATABASE_VERSION= 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
public static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_name, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_HOT + " TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLES IF EXIST" + DATABASE_TABLE);
onCreate(db);
}
}
public HotorNot(Context c){
ourContext = c;
}
public HotorNot open() throws SQLException {
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
ourHelper.close();
}
public long createEntry(String name, String hotness) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, name);
cv.put(KEY_HOT, hotness);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String []{ KEY_ROWID, KEY_NAME, KEY_HOT};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String results = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int iHotness = c.getColumnIndex(KEY_HOT);
for (c.moveToFirst(); !c.isAfterLast();c.moveToNext()){
results = results + c.getString(iRow) + " " + c.getString(iHotness) + " " + c.getString(iName)+"\n";
}
return results;
}
public String getName(long l) {
// TODO Auto-generated method stub
String[] columns= new String []{KEY_ROWID, KEY_NAME,KEY_HOT};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "_" + l, null, null, null, null);
if (c != null ){
c.moveToFirst();
String name = c.getString(1);
return name;
}
return null;
}
public String getHotness(long l) {
// TODO Auto-generated method stub
String[] columns= new String []{KEY_ROWID, KEY_NAME,KEY_HOT};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null);
if (c != null ){
c.moveToFirst();
String hotness = c.getString(2);
return hotness;
}
return null;
}
}