SwipeStack icon indicating copy to clipboard operation
SwipeStack copied to clipboard

Not working with object list

Open Durgaprasad1541996 opened this issue 7 years ago • 0 comments

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    try {

                        JSONArray jsonArray = response.getJSONArray("articles");
                        Log.e("e1",""+jsonArray.toString());
                        List<NewsApiOrgCard> topHeadlinesArray = new ArrayList<>();
                        for(int i=0;i<jsonArray.length();i++){
                            JSONObject headline = jsonArray.getJSONObject(i);
                            NewsApiOrgCard card = new NewsApiOrgCard();
                            card.setAuthor(headline.getString("author"));
                            card.setDescription(headline.getString("description"));
                            card.setTitle(headline.getString("title"));
                            card.setUrl(headline.getString("url"));
                            card.setUrlToImage(headline.getString("urlToImage"));
                            card.setPublishedAt(headline.getString("publishedAt"));
                            topHeadlinesArray.add(card);
                        }

                        swipeStack.setAdapter(new NewsApiOrgSwipeAdapter(topHeadlinesArray));
                        }catch (JSONException e){
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO: Handle error

                }
            });

     // Add the request to the RequestQueue.
    // Access the RequestQueue through your singleton class.
    MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest);
}

public class NewsApiOrgSwipeAdapter extends BaseAdapter { private List<NewsApiOrgCard> mData ; private Context context ;

public NewsApiOrgSwipeAdapter(List<NewsApiOrgCard> data) {
    this.mData = data;
}

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

}

@Override
public NewsApiOrgCard getItem(int position) {
    return mData.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.news_api_org_news_card, parent, false);
    TextView stackCardTitle = (TextView) convertView.findViewById(R.id.stackcardtitle);
    TextView stackCardDescription = (TextView) convertView.findViewById(R.id.stackcarddescription);
    TextView stackCardAuthor = (TextView) convertView.findViewById(R.id.stackcardauthor);
    TextView stackCardPublishedAt = (TextView) convertView.findViewById(R.id.stackcardpublishedat);
    NewsApiOrgCard newsApiOrgCard = mData.get(position);
    stackCardTitle.setText(newsApiOrgCard.getTitle());
    stackCardDescription.setText(newsApiOrgCard.getDescription());
    stackCardAuthor.setText(newsApiOrgCard.getAuthor());
    stackCardPublishedAt.setText(newsApiOrgCard.getPublishedAt());
    return convertView;
}

}

Durgaprasad1541996 avatar May 07 '18 06:05 Durgaprasad1541996