我需要在現有更多的數據我從數據庫中獲取ListView控件添加,不過,使用「更多」按鈕而不啓動或刷新活動。更新或新的數據合併arrayadapter - 按鈕更
我以這種方式使用adapter.AddAll(NewAdapter),但它只顯示列表中的地址(我認爲就是它)行,正如你可以在單擊更多後添加的行中的圖像中看到的那樣他沒有確定xml字段。但適配器是相同的,只有在新的Adpter正確顯示時才創建新的列表視圖。
什麼建議嗎?
@Override
protected void onPostExecute(List<RssItem> result) {
progressBar.dismiss();
// Get a ListView from main view
ListView itcItems = (ListView) findViewById(R.id.listMainView);
if (Integer.parseInt(limit) < 1) {
adapter = new ArrayAdapter<RssItem>(local, android.R.layout.simple_list_item_1, result);
itcItems.setAdapter(adapter);
itcItems.setOnItemClickListener(new ListListener(result, local));
} else {
Nadapter = new ArrayAdapter<RssItem>(local, android.R.layout.simple_list_item_1, result);
if (Nadapter.getCount() == 0){
final Button btMais = (Button) findViewById(R.id.btMais);
btMais.setVisibility(View.GONE);
Toast.makeText(getBaseContext(), "Don't more data.", Toast.LENGTH_SHORT).show();
} else {
adapter.addAll(Nadapter);
itcItems.setAdapter(adapter);
itcItems.setOnItemClickListener(new ListListener(result, local));
}
}
}
結束碼,並幫助Shadab運行:
@Override
protected void onPostExecute(List<RssItem> result) {
progressBar.dismiss();
// Get a ListView from main view
ListView itcItems = (ListView) findViewById(R.id.listMainView);
if (Integer.parseInt(limit) < 1) {
adapter = new ArrayAdapter<RssItem>(local, android.R.layout.simple_list_item_1, result);
itcItems.setAdapter(adapter);
itcItems.setOnItemClickListener(new ListListener(result, local));
} else {
Nadapter = new ArrayAdapter<RssItem>(local, android.R.layout.simple_list_item_1, result);
if (Nadapter.getCount() == 0){
final Button btMais = (Button) findViewById(R.id.btMais);
btMais.setVisibility(View.GONE);
Toast.makeText(getBaseContext(), "Don't more data.", Toast.LENGTH_SHORT).show();
} else {
adapter.addAll(result);
adapter.notifyDataSetChanged();
}
}
}
如果你想一些新的數據添加到您的適配器,您必須「通知它」使用** notifyDataSetChanged()**(它增加了新的數據和刷新列表視圖)希望它幫助! –