android table effect ListView interlacing color change implementation code

  • 2020-05-09 19:17:27
  • OfStack

First, inherit 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};// There is no reference to use here , It simply refers to an array operation  
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)); // Color Settings  
else 
view.setBackgroundColor(Color.argb(255, 224, 243, 250));// Color Settings  
return view; } } 

Second, use an overloaded Adapter for the effect
 
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); 
} 

In fact, it is mainly needed to overload SimpleAdapter, I quote the network point of view to write

Related articles: