を使用して、ビューをグリッドからリストに、リストからグリッドに変更しようとしていますRecyclerview。最初にアプリを実行すると、最初の画像のようにグリッド形式で表示されます
アイコンをクリックしてビューをグリッドからリストに変換すると、このようにリスト方式で表示されます
2.
- しかし、アイコンをもう一度クリックしてビューを変更すると、適切な出力が得られます
今の問題は、1 つのスクリーンショットで述べたように、グリッド方式でビューを取得できない理由です。
oncreateview
gridimg.setOnClickListener(this);
llm = new LinearLayoutManager(ProductListActivity.this);
rv = (RecyclerView)findViewById(R.id.recycler_viewproduts);
rv.setLayoutManager(llm);
ボレーと設定アダプターを使用してJson応答を取得する
private void makeJsonArrayRequest() {
showpDialog();
JsonArrayRequest req = new JsonArrayRequest( url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("ress", response.toString());
productlist = new ArrayList<ProductListModel>();
// Parsing json
ch_list = new ArrayList<String>();
color_list=new ArrayList<String>();
try {....................
rvAdapter = new RecyclerViewAdapter(ProductListActivity.this,productlist,ch_list);
rv.setAdapter(rvAdapter);
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
hidepDialog();
// notifying list adapter about data changes
// so that it renders the list view with updated data
//adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("ErrorVolley", "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
hidepDialog();
}
});
MyApplication.getInstance().addToReqQueue(req, "jreq");
}
オンクリック
case R.id.product_grid:
Toast.makeText(ProductListActivity.this, "Refresh App", Toast.LENGTH_LONG).show();
isViewWithCatalog = !isViewWithCatalog;
supportInvalidateOptionsMenu();
//loading = false;
rv.setLayoutManager(isViewWithCatalog ? new LinearLayoutManager(this) : new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
rv.setAdapter(rvAdapter);
break;


