0

我的 FeedItem Serializable 类有 http json 数组对象,我用它来填充列表视图。一切正常,但是在另一个片段上,我有一个文本视图,我想用我下载的 json 数组中的一个字符串填充它,我尝试了很多方法,但仍然无法做到。

这是json下载后开始的空白

public void updateList() {

    **TextView infoz = (TextView) getView().findViewById(R.id.infoz);**
    infoz.setText(getString(feedList))

    feedListView= (ListView)getActivity().findViewById(R.id.custom_list);
    feedListView.setAdapter(new CustomListAdapter(getActivity(), feedList));
    feedListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            Object o = feedListView.getItemAtPosition(position);
            FeedItem Data = (FeedItem) o;


            Intent intent = new Intent(getActivity(), FeedDetailsActivity.class);
            intent.putExtra("feed", Data);
            startActivity(intent);
        }
    });
}

feedList 是一个带有下载 json 的数组。我应该如何使用字符串并将其设置在 textview 中?谢谢

自定义列表适配器

    public class CustomListAdapter extends BaseAdapter {

    private ArrayList<FeedItem> listData;

    private LayoutInflater layoutInflater;

    private Context mContext;

    public CustomListAdapter(Context context, ArrayList<FeedItem> listData) {
            this.listData = listData;
            layoutInflater = LayoutInflater.from(context);
            mContext = context;
    }

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

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

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


    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                    convertView = layoutInflater.inflate(R.layout.list_row_layout, null);
                    holder = new ViewHolder();
                    holder.headlineView = (TextView)convertView.findViewById(R.id.title);
                    holder.reportedDateView = (TextView) convertView.findViewById(R.id.date);
                    holder.imageView = (ImageView) convertView.findViewById(R.id.thumbImage);

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

            FeedItem newsItem = (FeedItem) listData.get(position);
            holder.headlineView.setText(newsItem.getTitle());
            holder.reportedDateView.setText(newsItem.getDate());

            if (holder.imageView != null) {
                    new ImageDownloaderTask(holder.imageView).execute(newsItem.getAttachmentUrl());
            }

            return convertView;
    }

    static class ViewHolder {

            TextView headlineView;
            TextView reportedDateView;
            ImageView imageView;
    }




    }

json

 public void parseJson(JSONObject json) {
      try {

              // parsing json object
              if (json.getString("status").equalsIgnoreCase("ok")) {
               JSONArray posts = json.getJSONArray("posts");




                feedList = new ArrayList<FeedItem>();

                for (int i = 0; i < posts.length(); i++) {
                JSONObject post = (JSONObject) posts.getJSONObject(i);
                FeedItem item = new FeedItem();

         item.setTitle(post.getString("title"));
         item.setDate(post.getString("description"));
         item.setId(post.getString("id"));
         item.setUrl(post.getString("url"));
         item.setContent(post.getString("description"));


     JSONArray attachments = post.getJSONArray("attachments");
      ;
   if (null != attachments && attachments.length() > 0) {
     JSONObject attachment = attachments.getJSONObject(0);
     if (attachment != null)
        item.setAttachmentUrl(attachment.getString("url"));
          }

            feedList.add(item); 

              }

               } 
4

0 回答 0