0

By getting data from server displaying custom list-view. List item is having one button and one textview. Here i'm trying to display another listview with selected listview data.Here selection is done when when user click on button in list item.I'have done upto getting selected data from first Listview and storing it in arraylist.after this how to use this arraylist(Which is present in adapter class) and display a listview below the first listview.How to proceed.Here is my firstlistview adapter class

 package com.spatel.slantright.adapter;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.parse.SaveCallback;
import com.spatel.slantright.R;
import com.spatel.slantright.model.ManagerModel;
import com.spatel.slantright.model.UserDetials;

public class ManagersAdapter extends BaseAdapter {

    Context context;
    private List<UserDetials> rowItem = null;
    private List<UserDetials> notFollowing = null;
    LayoutInflater mInflater, notFollowinflater;
    boolean state[] = { true, true, true, true };





    public ManagersAdapter(Context context, List<UserDetials> alFollowings) {
        this.context = context;
        this.rowItem = alFollowings;

        this.mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    }

    /* private view holder class */
    private class ViewHolder {

        ImageView ivBlack;
        TextView tvUsername;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final UserDetials row_pos;
        row_pos = rowItem.get(position);
        ViewHolder holder = null;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.row_managers, null);
            holder = new ViewHolder();

            holder.ivBlack = (ImageView) convertView.findViewById(R.id.ivBlack);
            holder.tvUsername = (TextView) convertView
                    .findViewById(R.id.tvUsername);
            convertView.setTag(holder);
        }

        else {
            holder = (ViewHolder) convertView.getTag();
        }

        // setting the image resource and title


        //holder.ivBlack.setImageResource(rowItem.get(position).getIcon());
        holder.tvUsername.setText(rowItem.get(position).getUserName());

        holder.ivBlack.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (state[position]) {
                    row_pos.setIcon(R.drawable.black_circle);
                    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                            "UserDetails");
                    query.whereEqualTo("userId", ParseUser.getCurrentUser()
                            .getObjectId().toString());
                    query.findInBackground(new FindCallback<ParseObject>() {

                        @Override
                        public void done(List<ParseObject> object,
                                ParseException e) {

                            ParseObject objects = object.get(0);
                            if (e == null) {

                                try {

                                    JSONArray jArray = objects
                                            .getJSONArray("followings");
                                    JSONArray notfollowingJArray = new JSONArray();
                                    final JSONArray followingJArray = new JSONArray();

                                    if (jArray != null && jArray.length() > 0) {
                                        // alFollowings = new
                                        // ArrayList<UserDetials>();
                                        for (int i = 0; i < jArray.length(); i++) {
                                            // Excluding the item at position
                                            System.out
                                                    .println("POSITION ::::::::::::::::"
                                                            + position);
                                            if (i != position) {

                                                followingJArray.put(jArray.get(i));

                                            }else {
                                                System.out
                                                        .println("RRRRRRRRRRRRRRRRRRRRROOOOOOOOOOOOOOOOOOOOWWWWWWWWWWWWWWW" + rowItem.get(i).getUserName().toString());
                                                followingJArray.put(jArray.get(i));
                                                ArrayList<String> listdata = new ArrayList<String>();  
                                                if (jArray != null) { 
                                                       for (int j=0;j<jArray.length();j++){ 
                                                        listdata.add(jArray.get(j).toString());
                                                       } 
                                                    } 

                                            }
                                            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                                                    "UserDetails");
                                            query.whereEqualTo("userId", ParseUser.getCurrentUser()
                                                    .getObjectId().toString());
                                            query.findInBackground(new FindCallback<ParseObject>() {
                                                @Override
                                                public void done(List<ParseObject> object,
                                                        ParseException e) {

                                                    ParseObject objects = object.get(0);

                                                    objects.put(
                                                            "followings",
                                                            followingJArray);
                                                    objects
                                                            .saveInBackground();


                                                }
                                            });
                                        }

                                    }
                                } catch (JSONException e1) {
                                    e1.printStackTrace();
                                }

                            }

                        }
                    });

                    state[position] = false;
                    rowItem.remove(position);
                    notifyDataSetChanged();
                } else if (!state[position]) {
                    row_pos.setIcon(R.drawable.black_circle);
                    state[position] = true;
                    notifyDataSetChanged();
                }
            }
        });

        return convertView;
    }

    @Override
    public int getCount() {
        return rowItem.size();
    }

    @Override
    public Object getItem(int position) {
        return rowItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return rowItem.indexOf(getItem(position));
    }
}
Prabha1
  • 233
  • 1
  • 4
  • 22
  • For this way you not using ExpandableListView ? check : http://developer.android.com/reference/android/widget/ExpandableListView.html – Haresh Chhelana Nov 05 '14 at 06:35
  • i know it but it is not required.. – Prabha1 Nov 05 '14 at 06:37
  • You can use [enter link description here][1] [1]: http://stackoverflow.com/questions/24034754/how-to-get-data-from-custom-adapter-in-listview – Minp Nov 05 '14 at 06:43
  • If you see my code ,I already completed upto that.I'm able to get data from first listview and stored in arraylist.issue is how to get the arraylist from adapterclass and displaying in listview. – Prabha1 Nov 05 '14 at 06:50
  • You did nit tell at which moment the data should be used for the second listview. Nor what the user should do to invoke this. Is it all in the mentioned button click? – greenapps Nov 05 '14 at 09:32
  • Yes,It is mentioned in button click. – Prabha1 Nov 06 '14 at 10:36

0 Answers0