I have customised list view using BaseAdapter, I want to give separate color for the row position%5 ==0. but it also change the color some other rows which not satisfy the condition. Following is my getView().
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view=convertView;
if(convertView==null){
view=inflater.inflate(R.layout.groupl_ist, null);
}
TextView countryName=(TextView) view.findViewById(R.id.tvCountryText);
ImageView countryImage=(ImageView) view.findViewById(R.id.imgCountry);
String label=countryNames.get(position);
countryName.setText(label);
if(position%5==0){
countryImage.setVisibility(LinearLayout.GONE);
view.setBackgroundColor(Color.GREEN);
}else{
countryImage.setImageResource(R.drawable.ic_launcher);
}
return view;
}
countryImage.setVisibility(LinearLayout.GONE); tocountryImage.setVisibility(View.GONE); Also useViewHolderpattern for better performance.