I assume you know how to write an xml file with a dashed stroke. ask me if you need to know how to do it.
- Use two separate background xml files: background_yellow_stroke.xml and background_back_stroke.xml put them in a new res folder and name it: colors
- In your adapter's getView() method: use mod (%) operand to determine whether your position is even or odd.
public class MyCustomAdapter extends ArrayAdapter {
private List data;
private Activity context;
public NoteArrayAdapter(Activity context, int resID,
List<Note> data) {
super(context, resID);
this.data = data;
this.context = context;
}
@Override
public int getCount() {
return data.size();
}
@Override
public boolean isEmpty() {
return data.size() == 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convetView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView= inflater.inflate(R.layout.custom_list_item, parent, false);
}
if (position % 2 == 0) {
convertView.setBackgroundResource(R.colors.background_yellow_stroke.xml )
}
else
{
convertView.setBackgroundResource(R.colors.background_black_stroke.xml )
}
return convertView;
}
}
Done.