格式化一个 Textview,它列出了 Android Studio 中的所有 SQL table 条目
Format a Textview which lists all SQL table entries in Android Studio
我有一段代码列出了我的 table 的内容,其中包含具有各种结果的人员列表...
我能够获取在 Textview 中显示的值,如下所示:
1 鲍勃 0 0 0 0
2 蕾妮 0 0 0 0
3 杰森 0 0 0 0
4 桑迪 0 0 0 0
是否可以 "style" 对齐列内容?
如何设置列 "width"?!
这是检索数据的代码...
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 上使用 android:padding
和 android:margin
等属性将文本放置在页面上您希望的位置。然后,您还可以在一行中的每个值之间使用制表符分隔文本中的 "columns"。
String s1 = c.getString(0);
s1 = s1.replaceAll("\s","\t");
这样,尽管它们很长,但它们都将在一行上共享起始位置(当然,除非一个字符串超过制表符的长度,否则它可能会被移过来。)
我有一段代码列出了我的 table 的内容,其中包含具有各种结果的人员列表...
我能够获取在 Textview 中显示的值,如下所示:
1 鲍勃 0 0 0 0
2 蕾妮 0 0 0 0
3 杰森 0 0 0 0
4 桑迪 0 0 0 0
是否可以 "style" 对齐列内容? 如何设置列 "width"?!
这是检索数据的代码...
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 上使用 android:padding
和 android:margin
等属性将文本放置在页面上您希望的位置。然后,您还可以在一行中的每个值之间使用制表符分隔文本中的 "columns"。
String s1 = c.getString(0);
s1 = s1.replaceAll("\s","\t");
这样,尽管它们很长,但它们都将在一行上共享起始位置(当然,除非一个字符串超过制表符的长度,否则它可能会被移过来。)