i am trying to post a certain message per item with 2 Textviews, however the ListView on accepts 1 adapter and shows the data given by that adapter
the Screenshot shows that the data from the database has been retrieved and put in de ListView only the Small Text Data is missing.
Code:
public class ReservationsActivity extends AppCompatActivity {
List<String> subTextList = new ArrayList<>();
List<String> titleList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reservations);
listReservations = (ListView)
findViewById(R.id.listReservationsView);}
public void getReservations() {
subTextList = new ArrayList<>();
titleList = new ArrayList<>();
titleAdapter = new ArrayAdapter<>(this, R.layout.row, R.id.title, titleList);
subTextAdapter = new ArrayAdapter<>(this,R.layout.row,R.id.subText, subTextList);
listReservations.setAdapter(subTextAdapter);
listReservations.setAdapter(titleAdapter);
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ReservationsActivity.this);
String accessToken = prefs.getString("accessToken", null);
String web_adres = getString(R.string.web_adres);
String ip_adres = getString(R.string.ip_adres);
Ion.with(ReservationsActivity.this)
.load(web_adres + "/reservations?accessToken=" + accessToken)
.proxy(ip_adres, 8080)
.asJsonArray()
.setCallback(new FutureCallback<JsonArray>() {
@Override
public void onCompleted(Exception e, JsonArray result) {
jsonArray = result;
for (int i = 0; i < result.size(); i++) {
JsonObject jsonObject = result.get(i).getAsJsonObject();
JsonObject date = jsonObject.get("date").getAsJsonObject();
JsonObject time = jsonObject.get("time").getAsJsonObject();
String title = date.get("dayOfMonth").toString() + "/"
+ date.get("monthValue").toString() + "/"
+ date.get("year").toString();
String subtext;
if (time.get("id").getAsInt() == 1) {
subtext = getString(R.string.morning);
//imageInt = R.drawable.parking_morning;
} else if (time.get("id").getAsInt() == 2) {
subtext = getString(R.string.afternoon);
//imageInt = R.drawable.parking_afternoon;
} else if (time.get("id").getAsInt() == 3) {
subtext = getString(R.string.day);
//imageInt = R.drawable.parking_fullday;
} else
subtext = getString(R.string.day);
titleAdapter.add(title);
subTextAdapter.add(subtext);
//TODO set Image per item
//image.setImageResource(imageInt);
titleAdapter.notifyDataSetChanged();
subTextAdapter.notifyDataSetChanged();
}
}
});
return null;
}
};
task.execute();
}
how would one make it so that it populates all the items?