从源码Android中的TextView显示 [英] Textview display in Android from sqlite
问题描述
在我的应用程序有一个列表视图
,因为我从数据库中显示数据。
In my application I have one listview
, in that I am displaying data from database.
以下是我的code:
for(int i=1;i<=db.getAllTitles().getCount();i++)
{
String cat=db.getTitle(i).getString(5).toString();
Cursor c = db.gethouseholdTitle();
startManagingCursor(c);
if(cat.equals("Income"))
{
// System.out.println("inside if="+select);
// Cursor cin = db.income();
from = new String[] { db.KEY_INCOME,db.KEY_DESC,db.KEY_CATEGORY,db.KEY_QUANTITY,db.KEY_TOTAL};
to = new int[] {R.id.text1 ,R.id.text3,R.id.text5,R.id.text7,R.id.text9};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.columnview, c, from, to);
// System.out.println("notes="+notes.getCount());
// setListAdapter(notes);
lv.setAdapter(notes);
}
else
{
String catexp=db.getTitle(i).getString(5).toString();
Cursor cexp = db.gethouseholdTitleExp();
System.out.println("inside else="+cexp.getCount());
from = new String[] { db.KEY_INCOME,db.KEY_DESC,db.KEY_CATEGORY,db.KEY_QUANTITY,db.KEY_TOTAL};
to = new int[] {R.id.text2 ,R.id.text4,R.id.text6,R.id.text8,R.id.text10};
SimpleCursorAdapter notesexp =
new SimpleCursorAdapter(this, R.layout.columnview, cexp, from, to);
// System.out.println("notes="+notes.getCount());
// setListAdapter(notes);
lv.setAdapter(notesexp);
}
}
我的xml文件:
My xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/text1"
android:layout_width="30dip"
android:layout_height="wrap_content"
android:text="Price:"/>
<TextView android:id="@+id/text2"
android:layout_width="110dip"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="-20dp"
android:layout_weight="1"/>
<TextView android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/text4"
android:layout_marginTop="-20dp"
android:layout_width="110dip"
android:layout_height="wrap_content"
android:layout_marginLeft="180dp"
android:layout_weight="1"/>
<TextView android:id="@+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/text6"
android:layout_marginTop="-20dp"
android:layout_width="110dip"
android:layout_height="wrap_content"
android:layout_marginLeft="180dp"
android:layout_weight="1"/>
<TextView android:id="@+id/text7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/text8"
android:layout_marginTop="-20dp"
android:layout_width="110dip"
android:layout_height="wrap_content"
android:layout_marginLeft="180dp"
android:layout_weight="1"/>
<TextView android:id="@+id/text9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/text10"
android:layout_marginTop="-20dp"
android:layout_width="110dip"
android:layout_height="wrap_content"
android:layout_marginLeft="180dp"
android:layout_weight="1"/>
<TextView
android:id="@+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</LinearLayout>..
在此,得到只显示收入
数据。没有什么是显示为费用
。我检查数据库的费用算,它给精确的数目。这样的数据在数据库present,但没有得到显示。有没有在我的设计有问题?
In this, only income
data get displayed. Nothing is displaying for expense
. I checked database for expense count, it gives exact count. So data is present in database, but not get displayed. Is there any problem in my design?
推荐答案
本给出编码绘制布局,
<?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="wrap_content" >
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Show">
<TextView android:layout_width="50dp" android:layout_height="20dp" android:textColor="#ff8000"
android:id="@+id/Entry" android:layout_weight="1" android:gravity="left"/>
<TextView android:layout_width="50dp" android:layout_height="20dp" android:textColor="#ff8000"
android:id="@+id/sales" android:layout_weight="1" android:gravity="right" />
</TableRow>
您可以在这里添加TextView中的任何不,我想你想添加四个TextView的,所以你必须改变TextView的宽度为25dp。
You can add the any no of textview here,I think you want to add four textview so you has to change the textview width as 25dp.
因为给出的GridView编码然后设置simplecursoradapter
Then set simplecursoradapter for gridview coding as given
ada=new SimpleCursorAdapter(context, R.layout.showlist, mon,new String[] { cname, "_id" }, new int[] { R.id.Entry,R.id.sales })
gridview.setadapter(ada);
//It will work well.
最主要的是,你应该建立在GridView与提列的。
The main thing is you should create the gridview with mention the column is one.
这篇关于从源码Android中的TextView显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!