使用ArrayAdapter適配器來實現listview隔行換色的功能

工作中遇到的問題,在這裏記錄下。

重寫ArrayAdapter 使用方法與原來完全一樣。

public class colorAdapter extends ArrayAdapter {
    
    public colorAdapter (Context context, int view, String[] strings){
        super(context, view, strings);
    }

    //隔行變色
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view=super.getView(position,convertView,parent);

        if(position%2==0){
            view.setBackgroundColor(Color.argb(250, 255, 255, 255));
        }else{
            view.setBackgroundColor(Color.argb(255, 224, 243, 250));
        }
        return view;
    }

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章