Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a multicolumn recyclerView and have populated it with json data. the problem that i'm facing is that only one colum of the recyclerview is being populated the rest of them are not. the json object fetchs all the details but only one colum of recyclerView is populated. the code that i used is as follows


Java
public class FeedItem {
    private String hehw, hesub;

    String getHehw() {
        return hehw;
    }

    public void setHehw(String pname) {
        this.hehw = pname;
    }

    String getHesub() {
        return hesub;
    }

    public void setHesub(String name) {
        this.hesub = name;
    }    
}


Adapter.java
Java
private List<FeedItem> feedItemList;
    private Context mContext;

    public MyRecyclerAdapter(Context context, List<FeedItem> feedItemList) {
        this.feedItemList = feedItemList;
        this.mContext = context;
    }

    @Override
    public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.main_adapter, null);

        CustomViewHolder viewHolder = new CustomViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(CustomViewHolder customViewHolder, int i) {
        FeedItem feedItem = feedItemList.get(i);

       
        //Setting text view title
        customViewHolder.textView.setText(Html.fromHtml(feedItem.getHehw()));
        customViewHolder.textView.setText(Html.fromHtml(feedItem.getHesub()));
    }

    @Override
    public int getItemCount() {
        return (null != feedItemList ? feedItemList.size() : 0);
    }

    public class CustomViewHolder extends RecyclerView.ViewHolder {
       // protected ImageView imageView;
        protected TextView textView,textView1;

        public CustomViewHolder(View view) {
            super(view);
            //this.imageView = (ImageView) view.findViewById(R.id.thumbnail);
            this.textView = (TextView) view.findViewById(R.id.HeHw);
            this.textView1= (TextView) view.findViewById(R.id.HeSub);
        }
    }


and MainActivity.java
Java
@Override
        protected void onPostExecute(Integer result) {
            // Download complete. Let us update UI
            //progressBar.setVisibility(View.GONE);

            if (result == 1) {
                adapter = new MyRecyclerAdapter(MainActivity.this, feedsList);
                mRecyclerView.setAdapter(adapter);
            } else {
                Toast.makeText(MainActivity.this, "Failed to fetch data!", Toast.LENGTH_SHORT).show();
            }
        }

Java
private void parseResult(String result) {
        try {
            JSONObject response = new JSONObject(result);
            JSONArray posts = response.optJSONArray("RESTMethod");
            feedsList = new ArrayList<>();

            for (int i = 0; i < posts.length(); i++) {
                JSONObject post = posts.optJSONObject(i);
                FeedItem item = new FeedItem();
                item.setHehw(post.optString("ID"));
                item.setHesub(post.optString("SERIAL_NUMBER"));
                feedsList.add(item);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
Posted

1 solution

i got the problem solved.

in adapter class in the below function

@Override
public void onBindViewHolder(CustomViewHolder customViewHolder, int i) {
FeedItem feedItem = feedItemList.get(i);

->Change this
//Setting text view title
customViewHolder.textView.setText(Html.fromHtml(feedItem.getHehw()));
customViewHolder.textView.setText(Html.fromHtml(feedItem.getHesub()));
}

->to this
XML
customViewHolder.textView.setText(Html.fromHtml(feedItem.getHehw()));
       customViewHolder.textView1.setText(Html.fromHtml(feedItem.getHesub()));
 
Share this answer
 

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