android ListView动态加入了一个XML文件几个TextView,而我现在想单独改变某一个文本框的颜色,怎么改变啊
这些是MyAdapter代码,假如点击按钮时单独改变第二行第三个TextView颜色如何做到啊。。。classMyAdapterextendsBaseAdapter{pr...
这些是MyAdapter代码 ,假如点击按钮时单独改变第二行第三个TextView颜色 如何做到啊 。。。
class MyAdapter extends BaseAdapter{
private LayoutInflater mInflater;
public MyAdapter(Context context){
this.mInflater = LayoutInflater.from(context);
init();
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//System.out.println("position: " + position);
convertView = mInflater.inflate(R.layout.my_listitem3, null);
TextView t1 = (TextView) convertView.findViewById(R.id.textView1);
TextView t2 = (TextView) convertView.findViewById(R.id.textView2);
TextView t3 = (TextView) convertView.findViewById(R.id.textView3);
TextView t4 = (TextView) convertView.findViewById(R.id.textView4);
convertView.setTag(position);
t1.setText((String) mData.get(position).get("A"));
t2.setText((String) mData.get(position).get("B"));
t3.setText((String) mData.get(position).get("C"));
t4.setText((String) mData.get(position).get("D"));
t1.setTextColor(Color.GREEN);
t2.setTextColor(Color.BLUE);
t3.setTextColor(Color.RED);
t4.setTextColor(Color.YELLOW);
return convertView;
} 展开
class MyAdapter extends BaseAdapter{
private LayoutInflater mInflater;
public MyAdapter(Context context){
this.mInflater = LayoutInflater.from(context);
init();
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//System.out.println("position: " + position);
convertView = mInflater.inflate(R.layout.my_listitem3, null);
TextView t1 = (TextView) convertView.findViewById(R.id.textView1);
TextView t2 = (TextView) convertView.findViewById(R.id.textView2);
TextView t3 = (TextView) convertView.findViewById(R.id.textView3);
TextView t4 = (TextView) convertView.findViewById(R.id.textView4);
convertView.setTag(position);
t1.setText((String) mData.get(position).get("A"));
t2.setText((String) mData.get(position).get("B"));
t3.setText((String) mData.get(position).get("C"));
t4.setText((String) mData.get(position).get("D"));
t1.setTextColor(Color.GREEN);
t2.setTextColor(Color.BLUE);
t3.setTextColor(Color.RED);
t4.setTextColor(Color.YELLOW);
return convertView;
} 展开
1个回答
展开全部
LZ我有个思路给你,这里的getView方法会在Adapter的notifyDataSetChange时调用,也就是说,你可以在getView方法里面加个标识位,当这个标识位的值为变为XX时,第二行第三个TextView的颜色设置为XX颜色。然后在外部,点击按钮或其它事件时,改变这个标识位,再notifyDataSetChange即可。
追问
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.
请问遇到过这个问题没有,试了好多种办法,还是偶尔会出现这个问题。
追答
我倒是做过类似的,没遇到过。这个错误是说你有可能从其它后台线程改变了这个标识位,而不是从UI线程。你说偶尔遇到过,也就是说有时没问题,是什么情况遇到过?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询