如何到达列表视图的底部,装载更多的物品 [英] How to reach bottom of listview, load more items

查看:137
本文介绍了如何到达列表视图的底部,装载更多的物品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我达到我的ListView(向下滚动,直到结束)的底部,我怎么装入多个项目?
这里是我的类(也许它会帮助)

 公共类ListFood延伸活动{    INT用户ID;
    串猫;    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
      super.onCreate(savedInstanceState);
      的setContentView(R.layout.list_food);      LV的ListView =(ListView控件)findViewById(R.id.ListView01);
      TextView的电视=(的TextView)findViewById(R.id.TextView01);
      Webservice的WS =新的WebService();
      清单< Afood>名单=新的ArrayList< Afood>();
      INT I;      束束= getIntent()getExtras()。
      用户ID = bundle.getInt(用户id);
      猫= bundle.getString(猫);      清单= ws.getFoodFromCat(CAT);
      的String [] =食品新的String [则为list.size()];      对于(i = 0; I<则为list.size();我++)
      {
        食品[I] = list.get(I)。名称;
      }      如果(cat.equalsIgnoreCase(快餐))
          tv.setText(快餐);
      其他
          tv.setText(猫);      lv.setAdapter(新ArrayAdapter<串GT;(这一点,R.layout.list食品));      lv.setTextFilterEnabled(真);      lv.setOnItemClickListener(新OnItemClickListener(){
        公共无效onItemClick(适配器视图<>母公司,观景,
            INT位置,长的id){
          //单击时,显示的文字TextView的敬酒
          Toast.makeText(getApplicationContext(),((TextView的)视图).getText()
              Toast.LENGTH_SHORT).show();
        }
      });
    }}


解决方案

在除了回答@jleedev前提是,你还可以用我的 EndlessAdapter 这一点。

When I reach the bottom of my ListView (Scroll down until the end), how do I load more items? Here is my class (maybe it will help)

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();
        }
      });
    }

}

解决方案

In addition to the answer that @jleedev provided, you can also use my EndlessAdapter for this.

这篇关于如何到达列表视图的底部,装载更多的物品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆