-1
我想在ListView的1行中顯示2條數據,但是我卡住了。JSON的自定義列表視圖
我的問題是在showList()
方法。我無法使用自定義ListView XML顯示2個數據,我只能顯示1個數據。我想在我的自定義ListView中顯示item
和itemsemail
數組,而不僅僅是item
。
這裏是我的自定義的ListView適配器代碼...所有你需要的是有兩個的TextView,你將你的數據源綁定到一個充氣佈局的適配器類的
private void getDosen() {
//Ketika Aplikasi mengambil data kita akan melihat progress dialog
final ProgressDialog loading = ProgressDialog.show(this,"Mengambil Data","Mohon tunggu..",false,false);
//Logging Interceptor
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
//set Level Log
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())//GsonConverter untuk parsing json
.client(httpClient.build())
.build();
RestAPI service = retrofit.create(RestAPI.class);
Call<Model> call = service.loadListDosen();
call.enqueue(new Callback<Model>() { //Asyncronous Request
@Override
public void onResponse(Call<Model> call, Response<Model> response) {
loading.dismiss();
List<Listdosen> dosen = response.body().getListdosen();
//memasukkan data dari varibel dosen ke dosens
dosens = dosen;
//memanggil method untuk menampilkan list
showList();
}
@Override
public void onFailure(Call<Model> call, Throwable t) {
}
});
}
private void showList() {
//String array untuk menyimpan nama semua nama dosen
String[] items = new String[dosens.size()];
String[] itemsemail = new String[dosens.size()];
for (int i = 0; i < dosens.size(); i++) {
items[i] = dosens.get(i).getNama();
itemsemail[i] = dosens.get(i).getEmail();
}
//Membuat Array Adapter for listview
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_dosen_listview, items);
//setting adapter untuk listview
listview.setAdapter(adapter);
}
查找關於如何使一個自定義的ArrayAdapter的教程。你無法用'ArrayAdapter' –