开发者

Android: change textview settings (setTextColor) in listview-row layout

Little complicated title, but i don't know how to tell in different way =D.

I have 1 activity and 2 layout xml files.

in 1st .xml i have listview and in 2nd .xml i have items, which representing row in listview. it looks like in this tutorial: http://ykyuen.wordpress.com/2010/01/03/android-simple-listview-using-simpleadapter/

my question is: how can i programmatically change textviews settings in 2nd .xml (in tutorial grid_item.xml)

if i call text1.setTextColor(Color.RED); , it throws me exception java.lang.Nu开发者_高级运维llPointerException


problem solved.
I made my own adapter:

public class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[] { 0x30FF0000, 0x300000FF };
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);
  int colorPos = position % colors.length;
  view.setBackgroundColor(colors[colorPos]);
  return view;
}

}

it is from same site, that i posted it. i wanted better solution, but it does the job.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜