0
Android的列表視圖改變顏色,我目前得到了ListView
Adaptor
。根據內容
如何根據ListView
項目更改ListView
的背景顏色?
i.e if(item.param1 == "some")
{
colour1
}
else
{
colour2
}
我的代碼
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[] { 0xFFFFFFFF, 0xFF000000 };
TextView tv1, tv2;
public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
view.setBackgroundColor(colors[colorPos]);
return view;
}
}
希望這是有道理的
你想改變'ListView'的背景或項目關聯的特定'View'的背景是什麼? – prolink007 2012-07-31 16:53:12
這可以幫助你:http://stackoverflow.com/questions/7086133/android-listview-change-attributes-of-particular-view/7086301#7086301 – MrZander 2012-07-31 17:59:24
@MrZander感謝那些幫助 – 2012-07-31 18:06:25