android: how i can make a list from database sqlite?
I want to make a list contains some username from my sqlite database. I want it has white background and black text. I felt difficult when find every tutorial thought me to use extends listactivity....is there any technique to make it ? here is some of my code in nir.java
setContentView(R.layout.changeplayer);
btnCreateN = (Button)findViewById(R.id.btnCreateNew);
btnCreateN.setOnClickListener(this);
btnSetP = (Button)findViewById(R.id.btnOK);
btnSetP.setOnClickListener(this);
//buat listview
lstUnameView = (ListView)findViewById(R.id.listUsername);
adapter = new ArrayAdapter <String>(this,
android.R.layout.simple_list_item_1, lstUname);
lstUnameView.setAdapter(adapter);
//koneksi ke db, ngambil username-username
helper = new sqlite(this, "tamadb", 1);
db1 = helper.getWritableDatabase();
c = db1.rawQuery("SELECT username FROM tama", null);
if(c.moveToFirst())
{
do
{
lstUname.add(c.getString(0));
}while(c.moveToNext());
}
helper.close();
and this my code in layout changeplayer
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android";
android:layout_width="fill_parent"
a开发者_JAVA百科ndroid:layout_height="fill_parent">
<ListView android:id="@+id/listUsername"
android:layout_width="fill_parent"
android:layout_height="350px"
android:drawSelectorOnTop="false"
android:background = "#FFFFFFFF"
android:cacheColorHint = "#191919" />
<Button android:id="@+id/btnCreateNew"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Create New"
android:layout_below="@id/listUsername"
android:layout_marginLeft="40px" />
<Button android:id="@+id/btnOK"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="OK"
android:layout_below="@id/listUsername"
android:layout_toRightOf="@id/btnCreateNew" />
</RelativeLayout>
Please help, i want to finish this project too...he9x..thx before...^^
If you want your whole app to have white background and black text you can set the theme for your app to Theme.Light
. Therefore you have to add the attribute android:theme="@android:style/Theme.Light"
to the element of the manifest file.
This is the layout.xml I have put together for a listview with white background and black text.
You need to set the colours list_bg and menu_text to white and black respectively in your res folder then call the layout and id in your activity.
As far as populating a listview there is a good example here with downloadable code:
http://www.youtube.com/watch?v=Awu7Rlsez_k
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/list_bg">
<TextView android:background="@color/list_bg"
android:textColor="@color/menu_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding ="10dp"
android:textSize="22sp"
android:textStyle="bold"
android:id="@+id/row" />
<ListView android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
精彩评论