Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project wherein I have to parse a JSON Array and show the values in a RecyclerView. The issue is that I am not able to show the data form JSON in the RecyclerView.

Here is my Activity class:

<blockquote class="quote"><div class="op">Quote:</div>public class ClientListActivity extends AppCompatActivity {

    private String groupId;
    private String clientId;
    private String clientName;
    private RecyclerView recyclerView;
    private List<ClientListData> clientListData = new ArrayList<>();
    private ClientListAdapter mClientListAdapter;

    protected void onCreate(Bundle savedInstanceState) {
        recyclerView = (RecyclerView) findViewById(;

        if(getIntent() != null) {

            Bundle bundle = getIntent().getExtras();
            try {

                JSONObject jsonClientListObject = new JSONObject(getIntent().getStringExtra("clientList"));
                //JSONArray clientArray = jsonClientListObject.getJSONArray("activeClients");

                JSONArray clientArray = jsonClientListObject.optJSONArray("activeClients");

                for(int i = 0 ; i < clientArray.length(); i++) {
                    ClientListData clientListData = new ClientListData();

                    clientId = clientListData.getClientId();
                    clientName = clientListData.getClientName();
                //String activeClients = jsonClientListObject.getJSONArray("activeClients").toString();

                groupId = bundle.getString("groupId");

                mClientListAdapter = new ClientListAdapter(R.layout.client_list_item, clientListData);
                RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());

                Log.e("Client List ********", jsonClientListObject.toString() + " group Id: " + groupId);
                Log.e("client id: " + clientId, "client name: " + clientName);
            } catch (JSONException e) {

and here are my Adapter and Model Class:

<blockquote class="quote"><div class="op">Quote:</div>public class ClientListAdapter extends RecyclerView.Adapter<ClientListAdapter.ViewHolder> {

    private int listItemLayout;
    private List<ClientListData> clientArrayList;

    public ClientListAdapter(int layoutId, List<ClientListData> clientArrayList) {
        this.listItemLayout = layoutId;
        this.clientArrayList = clientArrayList;

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(listItemLayout, parent, false);
        ViewHolder myViewHolder = new ViewHolder(view);

        return myViewHolder;

    public void onBindViewHolder(ClientListAdapter.ViewHolder holder, int position) {

        TextView clients = holder.clientList;


    public int getItemCount() {
        return clientArrayList == null ? 0:clientArrayList.size();

    static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public TextView clientList;
        private final Context context;

        public ViewHolder(View itemView) {

            context = itemView.getContext();

            clientList = (TextView) itemView.findViewById(;

        public void onClick(View v) {


Model Class:

public class ClientListData {

    String clientId;
    String clientName;

    public String getClientId() {
        return clientId;

    public void setClientId(String clientId) {
        this.clientId = clientId;

    public String getClientName() {
        return clientName;

    public void setClientName(String clientName) {
        this.clientName = clientName;

I would like to know what am I doing wrong here.

What I have tried:

I tried a lot of things but I am quite new to Android Development and I don't know where I am doing wrong
David Crow 30-Aug-17 10:00am    
I'm seeing multiple instances of clientListData. One belongs to ClientListActivity. The other is local to the for() loop. Is that intentional?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900