0
我試圖創建一個動態列表視圖創建列表視圖,之前是我ArticleListFragment內部使用這個在onCreate方法:,我現在想的Android使用適配器
JokeListAdapter jokeAdapter = new JokeListAdapter();
setListAdapter(jokeAdapter);
這造就了我一個ListView基於靜態項目根據我的API的項目創建ListViews。
目前,我有一個成功的響應運行這一點,但我沒有得到我的列表視圖的任何項目它仍然是空的:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
call = service.jokes();
call.enqueue(new retrofit2.Callback<Joke>() {
@Override
public void onResponse(Call<Joke> call, Response<Joke> response) {
if(response.isSuccessful()) {
List<Joke> jokes = response.body();
Log.e(TAG, "response is successful");
setListAdapter(new JokeListAdapter(jokes));
Log.e(TAG, "response is successful");
} else {
Log.e(TAG, "response is not successful");
System.out.println(response.errorBody());
}
}
@Override
public void onFailure(Call<Joke> call, Throwable t) {
Log.e(TAG, "response on failure");
}
});
}
這是我的適配器構造:
private class JokeListAdapter extends BaseAdapter {
public JokeListAdapter(List<Joke> jokes) {
Joke.ITEMS = jokes;
}
您好,感謝的答案目前我得到這個錯誤'無法解析符號jokeListAdapter'這裏'jokeListAdapter.setValue(笑話);'無效的方法'聲明返回類型這裏required''公衆的setValue(名單笑話) {' –
utdev
** public void setValue(List jokes)** not ** public setValue(List jokes)**我的錯誤我更新了我的答案。 –
哦,不要忘了我非常感謝:D – utdev