如何从服务器中提取数据?

时间:2016-05-12 07:05:10

标签: java android android-recyclerview recycler-adapter

我的对象是食物。的 List<Food> contents; ;如何从服务器中提取数据?如何显示食物名称?我使用这个库。

  • 此处为TestRecyclerViewAdapter

https://github.com/florent37/MaterialViewPager/blob/master/sample/src/main/java/com/github/florent37/materialviewpager/sample/TestRecyclerViewAdapter.java

我在TYPE_CELL:

的情况下改变了这一点
  view = LayoutInflater.from(parent.getContext())
                            .inflate(R.layout.list_item_card_promotion_item, parent, false);
TextView foodName = (TextView) view.findViewById(R.id.txt_food_name);
foodName.setText(contents.get(0).getName());
                    return new RecyclerView.ViewHolder(view) {
                    };
  • RecyclerViewFragment

https://github.com/florent37/MaterialViewPager/blob/master/sample/src/main/java/com/github/florent37/materialviewpager/sample/fragment/RecyclerViewFragment.java

我这样改变。

mRecyclerView.setHasFixedSize(true);

        NetworkEngine.getInstance().getFood(new Callback<List<Food>>() {
            @Override
            public void success(List<Food> foods, Response response) {
                mContentItems = foods;
                mAdapter = new RecyclerViewMaterialAdapter(new FoodRecyclerViewAdapter(foods));
                mRecyclerView.setAdapter(mAdapter);

                {
                    for (int i = 0; i < ITEM_COUNT; ++i)
                        mContentItems.add(new Food());
                    mAdapter.notifyDataSetChanged();
                }
            }
        });

0 个答案:

没有答案