Here is the brief tutorial of using the simple cursor adapter .This adapter get binded with the list view .This is used in case when you retrieve the value from the database and you want to show the values in the list view .So suppose you fetched the data from the database like this :-
public Cursor fetchbylevel(int levels) throws SQLException {
Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] {
KEY_SCORE , KEY_NAME, KEY_LEVEL },
KEY_LEVEL + "=" +levels, null, null,null, KEY_SCORE+" DESC", null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
Now the above method is returning the whole set of tuples in the cursor now we have to show this cursor in the database in the required manner suppose in the above I want to show the NAME and SCORE of the player in one activity. So that can be done by binding the listview by the simple cursor adapter. For that you first have to create an xml file the file code is given below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="130px" android:layout_height="40px" android:gravity="left">
<TextView android:text="manasp" android:id="@+id/name"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="40dp" android:textColor="#ff0000" android:typeface="serif"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="80px" android:layout_height="40px"
android:gravity="right">
<TextView android:text="96" android:id="@+id/score"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="40dp" android:textColor="#00ff00"></TextView>
</LinearLayout>
</LinearLayout>

So in the above we have defined the xml named as lists.xml in which we defined the layout which is to be shown in the list view binded with simple cursor adapter. Now we have to write the one line code where we have to bind the list view .
String from[]={dataadapter.KEY_NAME,dataadapter.KEY_SCORE};
int to[]={R.id.name,R.id.score};
adapter=new SimpleCursorAdapter(this, R.layout.lists, cs, from, to);
lv.setAdapter(adapter);
The above code represents the two String array one is from[] and the other is to[]. In from array we have to give the attributes to display from the database and in to we have to pass the xml id of the view which was created in the lists.xml .
IF YOU LIKE THIS POST PLEASE COMMENT ANY QUERIES REGARDING THE ABOVE POST CAN BE ASKED !!!!!!!
public Cursor fetchbylevel(int levels) throws SQLException {
Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] {
KEY_SCORE , KEY_NAME, KEY_LEVEL },
KEY_LEVEL + "=" +levels, null, null,null, KEY_SCORE+" DESC", null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
Now the above method is returning the whole set of tuples in the cursor now we have to show this cursor in the database in the required manner suppose in the above I want to show the NAME and SCORE of the player in one activity. So that can be done by binding the listview by the simple cursor adapter. For that you first have to create an xml file the file code is given below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="130px" android:layout_height="40px" android:gravity="left">
<TextView android:text="manasp" android:id="@+id/name"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="40dp" android:textColor="#ff0000" android:typeface="serif"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="80px" android:layout_height="40px"
android:gravity="right">
<TextView android:text="96" android:id="@+id/score"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="40dp" android:textColor="#00ff00"></TextView>
</LinearLayout>
</LinearLayout>
So in the above we have defined the xml named as lists.xml in which we defined the layout which is to be shown in the list view binded with simple cursor adapter. Now we have to write the one line code where we have to bind the list view .
String from[]={dataadapter.KEY_NAME,dataadapter.KEY_SCORE};
int to[]={R.id.name,R.id.score};
adapter=new SimpleCursorAdapter(this, R.layout.lists, cs, from, to);
lv.setAdapter(adapter);
The above code represents the two String array one is from[] and the other is to[]. In from array we have to give the attributes to display from the database and in to we have to pass the xml id of the view which was created in the lists.xml .
IF YOU LIKE THIS POST PLEASE COMMENT ANY QUERIES REGARDING THE ABOVE POST CAN BE ASKED !!!!!!!
dongtam
ReplyDeletegame mu
cho thue phong tro
http://nhatroso.com/
nhac san cuc manh
tổng đài tư vấn luật
http://dichvu.tuvanphapluattructuyen.com/
văn phòng luật
tổng đài tư vấn pháp luật
thành lập công ty
http://we-cooking.com/
chém gió
trung tâm ngoại ngữthường.
Trong khoảng thời gian này Nhạc Thành mặc dù có chúng nữ bên cạnh nhưng hắn tu luyện nên không có cơ hội gần gũi các nàng, lúc này Liễu Thanh Thanh vô hình trung đã khiến hắn bùng cháy cảm xúc.
Nhạc Thành khẽ vuốt ve lưng của nàng, sau đó di động xuống phía dưới chạm vào bờ mông căng tròn.
- Huynh hiện tại không được có ý đó, mau bỏ muội ra.
Liễu Thanh Thanh khẽ cất tiếng, toàn thân sớm đã tê liệt trong người của Nhạc Thành.
- Muội càng nói vậy ta càng không thể buông.
Nhạc Thành nhẹ nhàng luồn tay chạm vào ngực của nàng, sau đó di động xuống phía dưới chạm vào chỗ mềm mại dưới bụng.
Tuy là cách áo nhưng Liễu Thanh Thanh vẫn thẹn thùng vô cùng. Toàn thân không còn chút sức lực dựa vào người của hắn.