我已经使用意图创建了一个列表视图,但是为了改善我的应用程序的用户体验,我如何更改列表视图中所选项目的颜色,我直接使用 ListActivity 类而不是来自调色板的列表视图,所以我需要直接将代码添加到活动这里是我的代码
public class BreakfastListView extends ListActivity {
static final String[] breakfood = {
"Strawberry shake",
"Egg muffin",
"Morning sundae",
"Peanut butter pancakes w banana",
"Dippy eggs w marmite soldiers",
"Breakfast burrito",
"Ham and cheese muffin",
"Bacon, egg and cheese bagel",
"Yoghurt mashup",
"Hot cereal mashup"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, breakfood));
// Setting up the list array above
}
protected void onListItemClick(ListView lv, View v, int position, long id){
super.onListItemClick(lv, v, position, id);
String openbreakclass = breakfood[position];
if( "Strawberry shake".equals(openbreakclass))
{
Intent selectedIntent = new Intent(v.getContext(), Strawberry_Shake.class );
startActivity(selectedIntent);
} else if("Egg muffin".equals(openbreakclass))
{
Intent selectedIntent = new Intent(v.getContext(), Egg_muffin.class );
startActivity(selectedIntent);
}else if("Morning sundae".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Morning_sundae.class );
startActivity(selectedIntent);
}else if("Peanut butter pancakes w banana".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Peanut_butter_pancakes_w_banana.class );
startActivity(selectedIntent);
}else if("Dippy eggs w marmite soldiers".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Dippy_eggs_w_marmite_soldiers.class );
startActivity(selectedIntent);
}else if("Breakfast burrito".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Breakfast_burrito.class );
startActivity(selectedIntent);
}else if("Ham and cheese muffin".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Ham_and_cheese_muffin.class );
startActivity(selectedIntent);
}else if("Bacon, egg and cheese bagel".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Bacon_egg_and_cheese_bagel.class );
startActivity(selectedIntent);
}else if("Yoghurt mashup".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Yoghurt_mashup.class );
startActivity(selectedIntent);
}else if("Hot cereal mashup".equals(openbreakclass)){
Intent selectedIntent = new Intent(v.getContext(), Hot_cereal_mashup.class );
startActivity(selectedIntent);
}
}