在android listview加载更多不工作

时间:2013-04-29 06:28:51

标签: android android-listview

我曾尝试on scrolling load more,但它根本不用,我使用了以下代码:

错误:

04-29 15:55:22.682: E/AndroidRuntime(311): FATAL EXCEPTION: AsyncTask #2
04-29 15:55:22.682: E/AndroidRuntime(311): java.lang.RuntimeException: An error occured while executing doInBackground()
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.lang.Thread.run(Thread.java:1096)
04-29 15:55:22.682: E/AndroidRuntime(311): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.os.Handler.<init>(Handler.java:121)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.Dialog.<init>(Dialog.java:101)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.AlertDialog.<init>(AlertDialog.java:63)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.<init>(ProgressDialog.java:80)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.show(ProgressDialog.java:101)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.show(ProgressDialog.java:90)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.show(ProgressDialog.java:85)
04-29 15:55:22.682: E/AndroidRuntime(311):  at com.example.know.FirstActivity.Callpagedetails(FirstActivity.java:176)
04-29 15:55:22.682: E/AndroidRuntime(311):  at com.example.know.FirstActivity$LoadDataTask.doInBackground(FirstActivity.java:320)
04-29 15:55:22.682: E/AndroidRuntime(311):  at com.example.know.FirstActivity$LoadDataTask.doInBackground(FirstActivity.java:1)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-29 15:55:22.682: E/AndroidRuntime(311):  ... 4 more

当我滚动时我得到的页数正在增加,但我没有得到数据可以有人帮我这个..

我使用了以下库load more in android

2 个答案:

答案 0 :(得分:0)

异常消息“无法在未调用Looper.prepare()的线程内创建处理程序”非常清楚。

如果需要Handler实例,则必须在GUI Thread中创建此对象。 您的活动的onCreate()方法是这个

的一个非常好的地方
class MyActivity implements Activity {

    ...
    private Handler handler;

    onCreate(...) {
       ....
       handler=new Handler();

答案 1 :(得分:0)

尝试:

private void refreshList() {    
Thread threadLoadMore = new Thread(new Runnable() {
   public void run() {  

       //Here refresh your arraylist 

    runOnUiThread(new Runnable() {
      public void run() {       
           //Here refresh your list view
           yourAdapter.notifyDataSetChanged();
        }
      });
    }
  });
  threadLoadMore .start();  
}