MyListView
看起来很棒,它正在从服务器加载新闻并将它们放在ListView
. 所以我想做的就是用另一种颜色制作最新的新品,但这不能通过检查来工作:if(position==0)
因为不仅第一项将布局修改为我选择的颜色,而且第三项也改变了布局。不知道为什么是第3个。下面是我的代码:
class simpleadapter extends SimpleAdapter
{
public simpleadapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final View view = super.getView(position, convertView, parent);
//final TextView tvTitle = (TextView)view.findViewById(R.id.tvTitle);
//final TextView tvContent = (TextView)view.findViewById(R.id.tvContent);
final RelativeLayout rl = (RelativeLayout)view.findViewById(R.id.rl);
if(position == 0)
rl.setBackgroundColor(Color.parseColor("#f0f0f0"));//here 'im changing the layout
holding the item in another color.
rl.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
/* tvTitle.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Log.i(JohnMain,"Click on the Textview! Congrats!!!");
Toast.makeText(MainActivity.this, "Congrats!", Toast.LENGTH_LONG).show();
}
});
*/
return view;
// return super.getView(position, convertView, parent);
}
}