簡體   English   中英

如何到達listview的底部,加載更多項目

[英]How to reach bottom of listview, load more items

當我到達ListView的底部(向下滾動直到結束)時,如何加載更多項目? 這是我的班級(也許會有所幫助)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM