当我到达 ListView 的底部(向下滚动到最后)时,如何加载更多项目? 这是我的类(class)(也许会有帮助)
public class ListFood extends Activity {
int userid;
String cat;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_food);
ListView lv = (ListView) findViewById(R.id.ListView01);
TextView tv = (TextView) findViewById(R.id.TextView01);
Webservice ws = new Webservice();
List<Afood> list = new ArrayList<Afood>();
int i;
Bundle bundle = getIntent().getExtras();
userid = bundle.getInt("userid");
cat = bundle.getString("cat");
list = ws.getFoodFromCat(cat);
String [] food = new String [list.size()];
for(i=0;i<list.size();i++)
{
food[i] = list.get(i).name;
}
if(cat.equalsIgnoreCase("FastFood"))
tv.setText("Fast Food");
else
tv.setText(cat);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list, food));
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
}
最佳答案
除了@jleedev 提供的答案,您还可以使用我的 EndlessAdapter
为此。
关于android - 如何到达 ListView 的底部,加载更多项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4731034/