2011-06-19 15 views
-1

私のリストに、sqliteデータベースのユーザ名が含まれているようにしたい。私は白い背景と黒のテキストが必要です。私はすべてのチュートリアルで、私がlistactivityを拡張するために使用すると思っていたのを見つけるのが難しいと感じました....それを作るテクニックはありますか?ここ は、レイアウトchangeplayerでnir.javaでの私のコードの一部android:データベースsqliteからリストを作成する方法は?

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(); 

と、この私のコード

<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; 
     android:layout_width="fill_parent" 
     android: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> 

私もこのプロジェクトを終了したい、助けてください... he9x..thxの前にあります... ^^

+0

ので、その後のFloの答えを見たら黒いテキスト(と白い背景を作る方法を、あなたの質問です:限り良い例は、ダウンロード可能なコードをここにあり、リストビューを移入するよう

またはListActivityの使い方を知りたいですか? – rhinds

+0

listactivityは私のコードを台無しにするでしょう、私はそれを読んで、それについて混乱させているので、he9x ....そして結局、私はlistactivityで他のコードを書く方法を知らない... he9x – marol

+0

私は使い方を見つけるでしょうテーマを最初に私は思う... he9x、thxの前に – marol

答えて

0

あなたのアプリ全体を白い背景と黒いテキストにしたい場合は、あなたのアプリのテーマをTheme.Lightに設定することができます。したがって、マニフェストファイルの要素に属性android:theme="@android:style/Theme.Light"を追加する必要があります。

+0

hmmm ...私はちょうどそのlistviewが白い背景と黒のテキストを持ってほしい... he9x。私はその属性を置く必要がありますか? – marol

+0

リストだけを黒色の背景で白くする必要がある場合は、リスト項目のカスタムレイアウトxmlを定義する必要があります。そこにあなたが好きなように色を設定します。 – Flo

+0

しかし、私は白い背景でリストを設定した場合、テキストは表示されません....>、< – marol

0

これは、私が白い背景と黒いテキストのリストビューにまとめたlayout.xmlです。

あなたのresフォルダの色は、それぞれlist_bgとmenu_textを白と黒に設定し、アクティビティのレイアウトとIDを呼び出す必要があります。

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> 
関連する問題