2011-01-19 67 views
3

當我到達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(); 
     } 
     }); 
    } 

} 
+1

[Android無盡列表]可能的重複(http://stackoverflow.com/questions/1080811/android-endless-list) – 2011-01-19 02:06:15

回答

相關問題