首页 > 代码库 > android表格效果--ListView隔行变色
android表格效果--ListView隔行变色
import meetweb.net.util.SpecialAdapter; 。。。。。 private SpecialAdapter simpleAdapter = null; public void ShowData(){ RateList = rateService.findAll(); System.out.println(RateList); LVrate=(ListView) this.findViewById(R.id.lvrate); simpleAdapter = new SpecialAdapter(this, RateList, R.layout.accuratelistitem, new String[]{"yearlimit","year1","year2"}, new int[]{R.id.tv_yearlimit,R.id.tv_year1,R.id.tv_year2}); LVrate.setAdapter(simpleAdapter); //listView.setOnItemClickListener(listener); }
package meetweb.net.util; import java.util.List; import java.util.Map; import android.content.Context; import android.graphics.Color; import android.view.View; import android.view.ViewGroup; import android.widget.SimpleAdapter; public class SpecialAdapter extends SimpleAdapter { private int[] colors=new int[]{0x30FF0000,0x300000FF};//这里没有引用进去使用,只是简单引用数组运算 public SpecialAdapter(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){ View view=super.getView(position, convertView, parent); int colorPos=position%colors.length; if(colorPos==1) view.setBackgroundColor(Color.argb(250, 255, 255, 255)); //颜色设置 else view.setBackgroundColor(Color.argb(255, 224, 243, 250));//颜色设置 return view; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。