如何将内容与其列标题对齐,我这里有下面的示例
姓名-----------------号码-----------------年龄
严 1232312 25
这是我查看 sqlite 数据库的 xml 代码
<?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>
这个是我的Activityclass来查看xml,你能教我把tablelayout参数放在哪里吗谢谢
`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;
}
}