データをRecyclerViewに設定しようとしています。データが表示されないRecyclerView
ここに応答データがあります。
[
{
"shopName": "Hello World.",
"shopTeluguName": "మమ్మీ",
"shopAddress": "Bomanahalli"
},
{
"shopName": "Hello World.",
"shopTeluguName": "మమ్మీ",
"shopAddress": "Bomanahalli"
},
{
"shopName": "Hello World.",
"shopTeluguName": "మమ్మీ",
"shopAddress": "Bomanahalli"
},
{
"shopName": "Hello.",
"shopTeluguName": "మమ్మీ",
"shopAddress": "Bomanahalli"
}
]
その解析とArrayListの中でそれを取得し、すべて正常に動作しているが、リサイクルのビューは、任意のデータを示していません。空の画面。レイアウト
public class ShopsAdapter extends RecyclerView.Adapter<ShopsAdapter.MyViewHolder> {
Activity activity;
private List<Shop> shopList;
public class MyViewHolder extends RecyclerView.ViewHolder {
LinearLayout linearLayoutParent;
public TextView textViewShopName, textViewShopTeluguName, textViewShopAddress;
public MyViewHolder(View view) {
super(view);
linearLayoutParent = (LinearLayout) view.findViewById(R.id.linearLayoutParent);
textViewShopName = (TextView) view.findViewById(R.id.textViewShopName);
textViewShopTeluguName = (TextView) view.findViewById(R.id.textViewShopTeluguName);
textViewShopAddress = (TextView) view.findViewById(R.id.textViewShopAddress);
}
}
public ShopsAdapter(Activity activity, List<Shop> shopList) {
this.activity = activity;
this.shopList = shopList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_shop, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
final Shop shop = shopList.get(position);
holder.textViewShopName.setText(shop.getShopName());
holder.textViewShopTeluguName.setText(shop.getShopTeluguName());
holder.textViewShopAddress.setText(shop.getShopAddress());
holder.linearLayoutParent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(activity, shop.getShopName(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return shopList.size();
}
}
:
はここで活動ここ
public class MainActivity extends AppCompatActivity implements WebServiceInterface {
Toolbar toolbar;
RecyclerView recyclerViewShops;
private int FETCH_SHOPS_REQUEST_CODE = 1;
ArrayList<Shop> arrayListShops;
ShopsAdapter adapterShops;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
fetchShops();
}
private void init() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Shops List");
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
toolbar.setTitleTextColor(Color.WHITE);
recyclerViewShops = (RecyclerView) findViewById(R.id.recyclerView);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
recyclerViewShops.setLayoutManager(mLayoutManager);
recyclerViewShops.setItemAnimator(new DefaultItemAnimator());
recyclerViewShops.setHasFixedSize(true);
arrayListShops = new ArrayList<>();
}
private void fetchShops() {
HashMap<String, String> paramsList = new HashMap<>();
WebServiceController webServiceController = new WebServiceController(
this, this);
String hitURL = LinksAndKeys.SHOPS_URL;
webServiceController.sendGETRequest("", "Loading..", hitURL, paramsList, FETCH_SHOPS_REQUEST_CODE);
}
@Override
public void getResponse(int responseCode, String responseString, String requestType, int requestCode) {
if (requestCode == FETCH_SHOPS_REQUEST_CODE && responseCode == 200) {
Gson gson = new Gson();
Shop[] shops = gson.fromJson(responseString, Shop[].class);
arrayListShops = new ArrayList<Shop>(Arrays.asList(shops));
adapterShops = new ShopsAdapter(this, arrayListShops);
recyclerViewShops.setAdapter(adapterShops);
}
}
}
がアダプターである場合の応答がファインです
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.saravanaeggdistributors.activities.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
、ArrayListには、データを持っていますが、 recyclerview does not show 。 ここで何が間違っていますか?
私はチェックしました。データはそこにあります。アダプタの内部でもデータは適切です。デバッガが2回目のアダプタのOnBindViewHolderのsettextメソッドに行くと消えます。 – Akshat
プロジェクトをデバッグしてテストできるようにプロジェクトを共有できますか? –
ここにあります。私はそれがあなたの側で正しく動作しないことを願っています! https://www.dropbox.com/s/cyr67cvmlwkj31q/Saravana.zip?dl=0 – Akshat