1

I am making an android app. I want to make List-view as above image. In this Listview I am fetching Items value from database using JSON webservice and how can change List-view Items border color and background image. Items 1,3,5,7,9 = same color and same background and List-view Items 2,4,6,8,10 = same color and same background. How can i do. please help me.

enter image description here

2
  • might be similar to this post Commented Feb 19, 2014 at 13:09
  • can you put your getView() method so that I could edit it for you? Commented Feb 19, 2014 at 13:09

2 Answers 2

1

Perhaps this tutorial can help you: android.amberfog.com

Just 2 types of items: in getView you doing almost the same, that in tutorial, but, instead of separator you setting your list item. HTH.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

  1. 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
  2. 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.

2 Comments

how can i put scissor in top right plach on dashed stroke.
@Amardeep: That's a complete question, but I'll answer it here: use two layouts, put the stroke to the inner layout and use layout_margin for it, put the sissor to the upper-right corner of the outer layout (use relative layout) and you are good to go :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.