0

私はAndroidが初めてで、3日前にSQLiteを使い始めました。データベースからリストを作成し、The Pragmatic Programmers - Hello Android に従っていくつかのビューを定義しましたが、問題があります。リストが表示されているときに項目を選択したい場合、リスト。リスト行xmlまたはリストビューxmlの定義で何かをしなければならないと確信しています。コード全体を投稿しますが。

validations_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/l_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/l_idcolon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": "
 />
<TextView
android:id="@+id/l_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 />
<TextView
android:id="@+id/L_namecolon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": "
/>
<TextView
android:id="@+id/av"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textStyle="italic"
 />
</LinearLayout>

testing.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- Note built-in ids for 'list' and 'empty' -->
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty" />
</LinearLayout>

そして、これが私の活動のコードです:

public class LinesListActivity extends ListActivity {

private static final String TAG = "ValidationsListActivity";
private static int [] TO = {R.id.l_id,R.id.l_name,R.id.av};


private DbManipulator dbm;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.testing);

    dbm = new DbManipulator(this);
    try
    {

        Cursor c = dbm.getLines();
        startManagingCursor(c);
        showEvents(c);
    }
    finally
    {

    }
}

private void showEvents(Cursor c) {

    SimpleCursorAdapter adapter = new   SimpleCursorAdapter(this,R.layout.validations_list,c,FROM_V,TO);
    setListAdapter(adapter);

}


@Override
public void onPause()
{
    super.onPause();
    dbm.close();
}
}

また、アプリ用に定義されたスタイルがありますが、それを通常のスタイルに戻すと、問題は残り、実際には何も変わりません。

4

1 に答える 1

1

セレクターは、デフォルトで透明に設定されているリストの背後に表示されるようにデフォルト設定されているため、それを通してセレクターを見ることができます。

背景に不透明な色を設定したので、セレクターを一番上に設定する必要があります。

これをリストビュー XML に追加します

android:drawSelectorOnTop="true"

それで直るはずです。

編集

よし、次のトリック。色状態セレクターを設定します。

1) フォルダーにカラー リストを作成し、valuesカラー名を 16 進数に設定します。

色.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="white">#ffffff</color>
    <color name="blue">#2554C7</color>
    <color name="green">#347C2C</color>
</resources>

drawable2)フォルダーにセレクターを作成します。

item_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
     android:state_pressed="true" 
     android:drawable="@color/green" />
</selector>

3) 最後に、セレクターをリスト行要素の背景として設定します。

android:background="@drawable/item_selector"

上記を使用すると、押している間、押していたリスト項目の背景が緑色になり、テキストが上に表示されたままになります。

于 2012-06-01T06:36:44.213 に答える