我正在尝试使用2个Textview发布每个项目的某个消息,但ListView on接受1个适配器并显示该适配器给出的数据
屏幕截图显示已检索到数据库中的数据并将其放入de ListView中,只缺少小文本数据。
代码:
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();
}
如何制作它以便填充所有项目?