【发布时间】:2015-02-13 16:09:50
【问题描述】:
我有一段代码列出了我的表格的内容,其中包含具有各种结果的人员列表...
我能够获得显示在 Textview 中的值,如下所示:
1 鲍勃 0 0 0 0
2 蕾妮 0 0 0 0
3 杰森 0 0 0 0
4 桑迪 0 0 0 0
是否可以对其进行“样式化”以使列内容对齐? 如何设置“宽度”列?!
这是检索数据的代码...
try
{
db=openOrCreateDatabase("mydatabase",SQLiteDatabase.CREATE_IF_NECESSARY,null);
Cursor c= db.rawQuery("SELECT * FROM mytable",null);
TextView v=(TextView)findViewById(R.id.v);
c.moveToFirst();
String temp="";
while(! c.isAfterLast()) {
String s1=c.getString(0);
String s2=c.getString(1);
String s3=c.getString(2);
String s4=c.getString(3);
String s5=c.getString(4);
String s6=c.getString(5);
temp=temp+"\n"+s1+"\t"+s2;
c.moveToNext();
}
v.setText(temp);
}
catch(SQLiteException e)
{
}
}
... 并将其放在以下 Textview 中:
<TextView
android:id="@+id/v"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
好的,非常感谢您!
【问题讨论】:
-
在单个 TextView 中确实没有什么好的方法可以做到这一点。您可能最好使用某种 TableLayout,或者使用结构更好的行来实现 ListView 以显示数据。您还应该在 for 循环中使用 StringBuilder 而不是使用字符串连接,并在完成后关闭光标。
标签: android sqlite android-studio