0
  1. I am getting json from php server.
  2. Depending upon the json I have to populate my listview.
  3. I have 2 section in my listview (Local users and International users)
  4. I have gone through following links to solve my issue:

Android, How to split ListView items into three parts?

ANDROID : split the screen in 2 equals parts with 2 listviews

http://codetheory.in/android-dividing-listview-sections-group-headers/

But the problem is I am using Custom Adapter with the Holder class for list view so it is unable to maintain it states.

anyone any suggestion or useful links to solve my issue.

here is my code:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = convertView;
        ViewHolder holder;

        if (null == view ) {
            view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.custom_list_item_one_on_one, parent, false);

            holder = new ViewHolder();
            holder.seprater = (TextView) view.findViewById(R.id.separator);
            holder.avatar = (RoundedImageView) view.findViewById(R.id.imageViewUserAvatar);
            holder.userName = (TextView) view.findViewById(R.id.textviewUserName);
            holder.userStatus = (TextView) view.findViewById(R.id.textviewUserStatus);
            holder.statusImage = (ImageView) view.findViewById(R.id.imageViewStatusIcon);
            holder.unreadCount = (TextView) view.findViewById(R.id.textviewSingleChatUnreadCount);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        Buddy buddy = getItem(position);

        Log.i("YES-1.0@!", buddy.separator + " / " + buddy.id + " / " + SECTIONED_LOCAL_BUDDID);

        if (SECTIONED_LOCAL_BUDDID == 0L)
            SECTIONED_LOCAL_BUDDID = buddy.id;

        if (buddy.separator.trim().equals("Local") && SECTIONED_STATE_LOCAL) {
            holder.seprater.setVisibility(View.VISIBLE);
            holder.seprater.setText("Local");
            SECTIONED_STATE_LOCAL = false;
        } else if (buddy.separator.trim().equals("International") && SECTIONED_STATE_INTERNATIONAL){
            holder.seprater.setText("International");
            holder.seprater.setVisibility(View.VISIBLE);
            SECTIONED_STATE_INTERNATIONAL = false;
        }
Community
  • 1
  • 1
Albert
  • 63
  • 1
  • 7
  • Check ExpandableListView, you can Use Groups to maintain both kinds of users. They will be grouped inside the ListView aus well. Ultimately it would look like the Phonebook App. Think of it as just 2 Groups of Contacts, one belonging to A another to B – Daniel Bo Feb 12 '16 at 16:29
  • You can use recyclerview. It has nice methods to handle layout types and state of item. Just give it try – Wasim K. Memon Feb 12 '16 at 17:24
  • Please post your code specially your "getView" method which will help us to find a solution. – Ruchira Randana Feb 12 '16 at 19:26
  • I have added my code – Albert Feb 13 '16 at 06:22

0 Answers0