我需要在ListView中添加我从数据库获得的更多数据,但是,使用"更多"没有开始或刷新活动的按钮。
我建议这样,使用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();
}
}
}
答案 0 :(得分:0)
您需要在适配器上添加项目而不是新的适配器。
答案 1 :(得分:0)
您无需创建新的适配器并进行合并,而是需要在现有适配器中设置新数据并使用notifyDataSetChanged()
进行刷新。
@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 {
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 {
//Whatever your initial list was add the new data in that list
oldList.addAll(result);
adapter.notifyDataSetChanged();
}
}
}