我有一個自定義BaseAdapter的列表視圖。列表視圖的每一行都有一個TextView和一個CheckBox。顯示自定義列表視圖的默認選擇顏色
問題是當我點擊(或觸摸)任何行時,textview前景變爲灰色,而不是默認行爲(背景 - >綠色,textview前景 - >白色)。
下面是代碼:
row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/layout">
<TextView android:id="@+id/main_lv_item_textView"
style="@style/textViewBig"
android:layout_alignParentLeft="true"/>
<CheckBox android:id="@+id/main_lv_item_checkBox"
style="@style/checkBox"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
自定義適配器:
public class CustomAdapter extends BaseAdapter {
private List<Profile> profiles;
private LayoutInflater inflater;
private TextView tvName;
private CheckBox cbEnabled;
public CustomAdapter(List<Profile> profiles) {
this.profiles = profiles;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return profiles.size();
}
public Object getItem(int position) {
return profiles.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View row = inflater.inflate(R.layout.main_lv_item, null);
final Profile profile = profiles.get(position);
tvName = (TextView) row.findViewById(R.id.main_lv_item_textView);
registerForContextMenu(tvName);
cbEnabled = (CheckBox) row.findViewById(R.id.main_lv_item_checkBox);
tvName.setText(profile.getName());
if (profile.isEnabled()) {
cbEnabled.setChecked(true);
}
tvName.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString(PROFILE_NAME_KEY, profile.getName());
Intent intent = new Intent(context, GuiProfile.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
tvName.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
selectedProfileName = ((TextView) v).getText().toString();
return false;
}
});
cbEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!profile.isEnabled()) {
for (Profile profile : profiles) {
if (profile.isEnabled()) {
profile.setEnabled(false);
Database.getInstance().storeProfile(profile);
}
}
}
profile.setEnabled(isChecked);
Database.getInstance().storeProfile(profile);
updateListView();
}
});
return row;
}
}
任何幫助,將不勝感激。