水平进度条没有从我的类扩展基本适配器加载

时间:2016-06-14 15:53:12

标签: java android listview

我有一个listview,它可以调整水平进度条对话框。进度条出现,但是没有加载请帮助我。我也得到空指针异常。

这是我为listview设置适配器的主要活动

  public class ListProgress extends ActionBarActivity {
        ListView lvProgress;
       public ProgressBarAdapter progressBarAdapter;
        public int pStatus;
        public ProgressBar progressBar;
        public Handler handler = new Handler();
        int budgetVal=600;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list_progress);
            lvProgress =(ListView) findViewById(R.id.lvProgress);
            progressBar =(ProgressBar) findViewById(R.id.progressBar1);
            progressBarAdapter = new ProgressBarAdapter(this);

            lvProgress.setAdapter(progressBarAdapter);
       }

这是扩展基本适配器的类。进度对话框显示正常,但根本无法加载。

public class ProgressBarAdapter extends BaseAdapter{
    TextView tv;
    private Handler handler = new Handler();
    public ViewHolder holder;
    private Context ctx;


        final class ViewHolder {
            public ProgressBar pBar;
        }

        public ProgressBarAdapter(Context ctx) {
            this.ctx = ctx;
        }

        @Override
        public int getCount() {
            return 1;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
             holder = new ViewHolder();
            LayoutInflater inflater=  (LayoutInflater) ctx.getSystemService(Context
                            .LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.activity_progress_dialog_demo, null);
             holder.pBar = (ProgressBar) convertView.findViewById(R.id.progressBar1);
            new myTask().execute();


//                    Thread t = new Thread(new Runnable() {
//                        int budgetVal = 600;
//                        int pStatus=0;
//                        @Override
//                        public void run() {
//                            // TODO Auto-generated method stub
//                            while (pStatus <= budgetVal) {
//
//                                handler.post(new Runnable() {
//
//                                    @Override
//                                    public void run() {
//                                        // TODO Auto-generated method stub
//                                        holder.pBar.setProgress(pStatus);
//                                        holder.pBar.setSecondaryProgress(pStatus + 5000);
//                                       // Toast.makeText(ctx,"Touched: " + pStatus ,Toast.LENGTH_LONG).show();
//                                    }
//                                });
//                                try {
//                                    // Sleep for 200 milliseconds.
//                                    // Just to display the progress slowly
//                                    Thread.sleep(50);
//                                } catch (InterruptedException e) {
//                                    e.printStackTrace();
//                                }
//                                pStatus++;
//                            }
//                        }
//                    });t.start();
            return convertView;
        }


    class myTask extends AsyncTask<Void, Void, Void>
    {
        int pStatus=0;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            holder.pBar .setMax(1200);
            holder.pBar .setProgress(pStatus);
            holder.pBar .setVisibility(View.VISIBLE);
            pStatus=0;
        }


        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
            pStatus++;
            holder.pBar .setProgress(pStatus);
        }

        @Override
        protected Void doInBackground(Void... params) {
            return null;

        }


    }

}

LogCat上的空指针异常

06-16 17:54:14.382  16120-16120/? E/dalvikvm﹕ >>>>> Normal User
06-16 17:54:14.382  16120-16120/? E/dalvikvm﹕ >>>>> com.example.fritzmichaelquaye.datedemo [ userId:0 | appId:10251 ]
06-16 17:54:14.712  16120-16120/com.example.fritzmichaelquaye.datedemo E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.fritzmichaelquaye.datedemo, PID: 16120
    java.lang.NullPointerException
            at com.example.fritzmichaelquaye.adapter.ProgressBarAdapter$myTask.onPreExecute(ProgressBarAdapter.java:125)
            at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
            at android.os.AsyncTask.execute(AsyncTask.java:535)
            at com.example.fritzmichaelquaye.adapter.ProgressBarAdapter.getView(ProgressBarAdapter.java:73)
            at android.widget.AbsListView.obtainView(AbsListView.java:2765)
            at android.widget.ListView.measureHeightOfChildren(ListView.java:1274)
            at android.widget.ListView.onMeasure(ListView.java:1186)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
            at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2548)
            at android.view.View.measure(View.java:17478)
            at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2259)
            at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1388)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1587)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6567)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
            at android.view.Choreographer.doCallbacks(Choreographer.java:603)
            at android.view.Choreographer.doFrame(Choreographer.java:573)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5476)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案