zoukankan      html  css  js  c++  java
  • android表格效果ListView隔行变色

    首先继承SimpleAdapter

    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; } }

     第二,使用重载的Adapter来达到效果

    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);
    }

    其实主要是需要重载SimpleAdapter,本人引用网络观点进行编写

  • 相关阅读:
    微软面试问题 情商测试
    SQL游标使用实例
    如何减小与“大牛”的差距
    Dotnet面试题
    排序算法对冒泡排序的优化改进算法
    一个SQL实现薪水大于所在部门平均薪水的员工
    ASP.NET中TextBox设置为Readonly后无法取值的解决办法
    jQuery.Autocomplete实现自动完成功能(详解)
    php发送get、post请求的几种方法
    ISO Latin1字符集
  • 原文地址:https://www.cnblogs.com/meetweb/p/2920630.html
Copyright © 2011-2022 走看看