作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
现在我有一个 ListView,其中充满了我的“位置”对象。我的 list 中最初有 10 项。当我读完时,我想再添加 10 个项目。
代码:
public class MainActivity extends ActionBarActivity {
ListView listView;
int startLoop, endLoop;
ArrayList<Location> arrayOfLocations;
LocationAdapter adapter;
Button refresh;
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
startLoop = 0;
endLoop = 10;
listView = (ListView) findViewById(R.id.listView1);
progress = new ProgressDialog(this);
listView.setOnScrollListener((OnScrollListener) this);
// Construct the data source
arrayOfLocations = new ArrayList<Location>();
// Create the adapter to convert the array to views
adapter = new LocationAdapter(this, arrayOfLocations);
FillLocations myFill = new FillLocations();
myFill.execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class FillLocations extends AsyncTask<Integer, Void, ArrayList<Location>> {
protected void onPreExecute() {
}
@Override
protected ArrayList<Location> doInBackground(Integer... params) {
for (int i = startLoop; i < endLoop; i++) {
String title = "Place " + Integer.toString(i);
locArray.add(new Location(title, "details","hours","distance:)));
}
return locArray;
}
protected void onPostExecute(ArrayList<Location> listOfLocs) {
// Attach the adapter to a ListView
for (Location location : listOfLocs)
adapter.add(location);
listView.setAdapter(adapter);
progress.dismiss();
}
}
}
所以基本上我想要这样的东西: 1.检测何时到达终点 2.loopStart和loopEnd加10 3.调用我的 FillLocations 任务
关于如何实现这一点有什么想法吗?谢谢
最佳答案
你要么想要:
填充新项目时加载文本/动画:How to display a "Loading..." text while retrieving items for a ListView
一个简单的无尽列表,没有花哨的东西:endless scroll list view in android
用户通过拉动刷新机制触发填充:How to implement Android Pull-to-Refresh
关于java - 如何在 ListView 到达末尾时向其添加项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24042875/
我是一名优秀的程序员,十分优秀!