android表格效果之ListView隔行變色實現代碼

來源:互聯網
上載者:User

首先繼承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,本人引用網路觀點進行編寫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.