1
私はAPIからJSONObject
にresponsedていると私はRecyclerview
アダプタに、その後セッターを使用してモジュールに応答を送信しようとしたが、JSON値をFragmentからモジュールに送信するにはどうすればよいですか?
を働いていないそのこれは私のフラグメント
public class ListViewActivityFragment extends Fragment {
List<AppShowModule> appShowModule;
RecyclerView AppRecyclerView;
List<AppShowModule> GetDataAdapter1;
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);
text = (TextView) getView().findViewById(R.id.textView2);
AppRecyclerView.setHasFixedSize(true);
GetDataAdapter1 = new ArrayList<>();
AppRecyclerView.setLayoutManager(AppRecyclerViewlayoutManager);
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();
text.setText(name);
appShowModule111.setAppName((name));}
} 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));
AppRecyclerViewadapter = new RecyclerViewAdapter(GetDataAdapter1,this);
AppRecyclerView.setAdapter(AppRecyclerViewadapter);
}
}
であり、これは私のアダプタ
ですpublic class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
Context context;
List<AppShowModule> getDataAdapter;
Context MContext;
public RecyclerViewAdapter(List<AppShowModule> getDataAdapter, ListViewActivityFragment context){
super();
this.getDataAdapter = getDataAdapter;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.appitem, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position)
{
final AppShowModule getDataAdapter1 = getDataAdapter.get(position);
holder.NameTextView.setText(getDataAdapter1.getAppName());
Picasso.with(context).load(getDataAdapter1.getAppImageUrl()).into(holder.imgPost);
}
@Override
public int getItemCount() {
return getDataAdapter.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public TextView NameTextView;
public ImageView imgPost;
LinearLayout lnrLayout;
public ViewHolder(View itemView) {
super(itemView);
NameTextView = (TextView) itemView.findViewById(R.id.appName);
imgPost = (ImageView) itemView.findViewById(R.id.appImage);
lnrLayout = (LinearLayout)itemView.findViewById(R.id.lnrLayout);
}
}
}
、これが私のモジュールである
public class AppShowModule
{
private String appName;
private String appImageUrl;
public String getAppName() {
return appName;}
public void setAppName(String appName) {
this.appName = appName;}
public String getAppImageUrl() {
return appImageUrl;}
public void setAppImageUrl(String appImageUrl) {
this.appImageUrl = appImageUrl;}
}
ありがとうございます(GetDataAdapter1、this)は適用できません。 –
試してみるAppRecyclerViewadapter =新しいRecyclerViewAdapter(GetDataAdapter1、ListViewActivityFragment.this); –
非常に働いてくれてありがとうございましたが、今はリサイクラービューでただ1つのアイテムが表示されていますが、私は50を持っています!なぜこれはちょうど1つを示していますか? –