アクティビティの開始時に必要なリストビューがあり、最初のアイテムには背景があり、他のアイテムには背景がありません。その後、ユーザーが他のアイテムを選択すると、その特定のアイテムの背景は青になります残りには背景がありません。これについて私を助けてください。
私のlayout_effect.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<shape>
<solid android:color="#ffffff" />
</shape>
</item>
<item>
<shape>
<solid android:color="#00a7eb" />
</shape>
</item>
</selector>
デフォルトの背景を設定している私のGetViewコード
public View getView(int position, View convertView, ViewGroup parent) {
if(position == 0){
vi.setBackgroundResource(R.drawable.selection_effect);
vi.setSelected(true);
}
}
リストビューの私のonclickListner
onewayListView .setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Clicked", 1000).show();
}
});
マイ リストビュー xml
<ListView
android:id="@+id/lvDepartures"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:choiceMode="singleChoice"
android:layout_height="wrap_content"
android:listSelector="@drawable/selection_effect"
android:layout_width="wrap_content"/>
この問題を解決する方法を教えてください。