android 列表常用颜色,根据列表android中的值更改listview中列表项的颜色

使用这段代码,我在这里给你一个偶数和奇数位置的例子(你可以像你一样改变位置上的条件)

ArrayAdapter adapter = new MyListAdapter();

listView = (ListView) findViewById(R.id.myListView);

listView.setAdapter(adapter);这是MyListAdapter的实现

public class MyListAdapter extends ArrayAdapter {

private class MyListAdapter extends ArrayAdapter {

public MyListAdapter() {

super(context, R.layout.ifact1_help2, R.layout.ifact1_help1, liste);

}

@Override

public int getCount() {

return yourListe.size();

}

@Override

public int getViewTypeCount() {

return 2;

}

@Override

public int getItemViewType(int position) {

if (position % 2 == 0) {

return 1;

}

return 0;

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

View itemView = convertView;

if (position % 2 == 0) {

itemView = getLayoutInflater().inflate(R.layout.textViewRed, parent, false);

itemView.setText(" your text");

} else {

itemView = getLayoutInflater().inflate(R.layout.textViewGreen, parent, false);

itemView.setText(" your text");

}

return itemView;

}

}这里是textViewRed.xml和green,你必须在目录布局上定义

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:singleLine="true"

android:paddingLeft="10dp"

android:textColor="@color/black"

android:background="@color/red"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:singleLine="true"

android:paddingLeft="10dp"

android:textColor="@color/black"

android:background="@color/green"

/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值