Попробуйте это @ Jsoe,
StringRequest stringRequest = new StringRequest(url , new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JsonObject object = new JsonObject(response);
String something = object.getString("something");
JsonObject jsonObject = new JsonObject(something);
ArrayList<Hashmap<String,String>> arraylist = new ArrayList<>();
for(int i= 0 ; i < jsonObject.length ; i++){
HashMap<String, String> hashMap = new HashMap<>();
String firstString = jsonObject.getString("String");
String differentString = jsonObject.getString("DifferentString");
String wayDifferentString =
jsonObject,getString("WayDifferentString");
hashMap.put("firstString ", firstString);
hashMap.put("differentString", differentString);
hashMap.put("wayDifferentString", wayDifferentString);
arraylist.add(hashMap);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(stringRequest);
//setting adapter data to the RecyclerView
private void attachAdapter(ArrayList<HashMap<String, String>>
arrayList) {
ExampleAdapter adapter = new ExampleAdapter(arrayList,this);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
Адаптер layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/firstString"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/differentString"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/WayDifferentString"
/>
Код адаптера:
public class ExampleAdpater extends
RecyclerView.Adapter<ExampleAdpater.ExampleViewHolder>{
public ArrayList<HashMap<String,String>> arraylist;
public Context context;
public ExampleAdpater(ArrayList<HashMap<String, String>> arraylist, Context context)
{
this.arraylist= arraylist;
this.context = context;
}
@NonNull
@Override
public ExampleViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view =
LayoutInflater.from(viewGroup.getContext()).
inflate(R.layout.textLayout,viewGroup,false);
return new ExampleViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ExampleViewHolder viewHolder, int i) {
HashMap<String,String> hashMap = arraylist.get(i);
viewHolder.name.setText(hashMap.get("firstString"));
viewHolder.tid.setText(hashMap.get("differentString"));
viewHolder.tid.setText(hashMap.get("wayDifferentString"));
}
@Override
public int getItemCount() {
return arraylist.size();
}
public class ExampleViewHolder extends RecyclerView.ViewHolder{
TextView string,differentString,wayDifferentString;
public ExampleViewHolder(@NonNull View itemView) {
super(itemView);
string = itemView.findViewById(R.id.string);
differentString = itemView.findViewById(R.id.differentString);
wayDifferentString = itemView.findViewById(R.id.differentString);
wayDifferentString.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),
""+wayDifferentString.getText().toString(),
Toast.LENGTH_SHORT).show();
}
});
}
}
}
Этопростой способ использовать формат ключ-значение.Сообщите мне, если у вас есть какие-либо вопросы с этим.