1
私はリストとしてこのrecyclerviewを持っており、グリッドビューに変更する必要があります。どのようにそれを行うことができますか?私はgridlayoutmangerを試みたが、それは動作していない。私はそれをどのように行うことができます(およびエラーを避けるため、あなたの時間に感謝recyclerviewをgridviewとして作成しますか?
これは断片である:?
public class ListViewActivityFragment extends Fragment {
List<AppShowModule> appShowModule;
RecyclerView AppRecyclerView;
List<AppShowModule> GetDataAdapter1;
private GridLayoutManager lLayout;
RecyclerView.LayoutManager AppRecyclerViewlayoutManager;
RecyclerView.Adapter AppRecyclerViewadapter;
String jsonUrl = "https://itunes.apple.com/jo/rss/topfreeapplications/limit=50/json";
TextView text;
Context context;
RequestQueue requestQueue;
public ListViewActivityFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_list_view, container, false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
appShowModule = new ArrayList<>();
AppRecyclerView = (RecyclerView) getView().findViewById(R.id.AppRecyclerView);
AppRecyclerView.setHasFixedSize(true);
lLayout = new GridLayoutManager(context, 4);
AppRecyclerView.setLayoutManager(lLayout);
GetDataAdapter1 = new ArrayList<>();
JsonAppShowData();
}
public void JsonAppShowData() {
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(jsonUrl, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONObject("feed").getJSONArray("entry");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json1 = jsonArray.getJSONObject(i).getJSONObject("im:name");
AppShowModule appShowModule111 = new AppShowModule();
String name = response.getJSONObject("feed").getJSONArray("entry").getJSONObject(i).getJSONObject("im:name").getString("label").toString();
String image = response.getJSONObject("feed").getJSONArray("entry").getJSONObject(i).getJSONArray("im:image").getJSONObject(0).getString("label").toString();
appShowModule111.setAppName((name));
appShowModule111.setAppImageUrl(image);
GetDataAdapter1.add(appShowModule111);
}
AppRecyclerViewadapter = new RecyclerViewAdapter(GetDataAdapter1,getContext());
AppRecyclerView.setAdapter(AppRecyclerViewadapter);
} catch (JSONException e) {
e.printStackTrace();
}}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("LOG", error.toString());
}
});
requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(jsonObjectRequest);
AppRecyclerView.setLayoutManager(new LinearLayoutManager(context));
}
}
ありがとうございました –
この質問を確認してください[リンク](http://stackoverflow.com/questions/39436616/error-in-parsing-json-array-to-picasso) –