-1

私は3つの異なるカスタム行の激しいインフレを伴うリストビューを持っています.これらの行からデータを収集し、データベースに入力し、最終的にそのデータも取得する必要があります.今問題は、作成される行の数がユーザーに依存することです.そして、リストのスクロールが非常に遅くなります。今知りたいのは、すべてのリスト機能を非同期タスクに入れると役立つかどうかです。つまり、その作成と実行を意味します。以下は私のコードスニペットです。

         private class Async extends AsyncTask<String, Integer, String>{

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            runOnUiThread(new Runnable() {
                 public void run() {
                     lv.setAdapter(new EfficientAdapterAB(Measure_New.this));
                        new EfficientAdapterAB(Measure_New.this).notifyDataSetChanged();
            //stuff that updates ui

                }
            });

            return null;
        }

     }


    private   class EfficientAdapterAB extends BaseAdapter {
            private LayoutInflater mInflater;
            View[] view; 
            ViewHolderAB holderAB;
            /*  RadioButton[] ob=new RadioButton[n];
              RadioButton[] ra=new RadioButton[n];*/

             AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(Measure_New.this);
                SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj.getReadableDatabase();
                String q="SELECT * FROM ab_measurement WHERE job_id=" +"\""+Settings.jobid +"\"";
                Cursor  cursor = sqliteDatabase.rawQuery(q,null);



             public EfficientAdapterAB(Context context) {
             mInflater = LayoutInflater.from(context);


             }

             public int getCount() {
                System.out.println("in getcount value of n is "+n);

                view = new View[n+2];
                return n+2;
             }

             public Object getItem(int position) {

             return position;
             }

             public long getItemId(int position) {

             return position;
             }


 public View getView(final int position,  View convertView, ViewGroup parent) {

    final RadioButton[] ob=new RadioButton[n];
    final  RadioButton[] ra=new RadioButton[n];



     holderAB = new ViewHolderAB();
     final EditText edit_a_ft,edit_a_inch,edit_b_ft,edit_b_inch,edit_ab_a_ft,edit_ab_a_inch,edit_ab_b_ft,edit_ab_b_inch;

if (view[position] == null) {
        if(position==0){
             convertView = mInflater.inflate(R.layout.measure_upper_bar, null);
             txt_ft_mtr=(TextView)convertView.findViewById(R.id.textView_ft_mtr);
             txt_inch_cm=(TextView)convertView.findViewById(R.id.textView_inch_cm);
             if(Settings.metric_count==1){
                 txt_ft_mtr.setText(""+"Meter");
                 txt_inch_cm.setText(""+"Centimeter");
             }
             user_input= (EditText) convertView.findViewById(R.id.Num_edittxt_measure_new);
             gettingUserInput();
             new EfficientAdapterAB(Measure_New.this).notifyDataSetChanged();
             System.out.println("after gettinguserInput value of n is "+n);
              feet=(EditText)convertView.findViewById(R.id.Feet_edittxt);
              inch =(EditText)convertView.findViewById(R.id.Inches_Edittxt);

              feet.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                    try{
                    val_feet_baseline=Integer.parseInt(feet.getText().toString());

                    }catch (Exception e) {
                        // TODO: handle exception
                    }

                }
            });

             inch.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub


                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                    try{

                        val_inch_baseline=Integer.parseInt(inch.getText().toString());

                        if(val_inch_baseline>=ft_mtr){
                            inch_greater=true;
                            ft_baseline=val_feet_baseline+(val_inch_baseline/ft_mtr);
                            val_inch_baseline=val_inch_baseline%ft_mtr;
                            feet.setText(""+ft_baseline);
                            inch.setText(""+val_inch_baseline);
                            System.out.println("yes its working values of feet and inch is "+"feet"+ft_baseline+"inch"+val_inch_baseline);

                        }
                    }
                    catch (Exception e) {
                        // TODO: handle exception
                    }
                }
            });

             if(inch_greater==true){
                 baseline_length=String.valueOf(ft_baseline).concat(".").concat(String.valueOf(val_inch_baseline));
                 feet.setText(""+ft_baseline);
                 System.out.println("in the if part");
                 inch_greater=false;
             }
             else{
             baseline_length=String.valueOf(val_feet_baseline).concat(".").concat(String.valueOf(val_inch_baseline));
             System.out.println("in the else part");
             feet.setText(""+val_feet_baseline);
             }

             inch.setText(""+val_inch_baseline);
                if(val_feet_baseline==0){
                     feet.setText(""+"");
                }

                if(val_inch_baseline==0){

                    inch.setText(""+"");
                }
             user_input.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        user_input.setText("");
                        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(user_input, InputMethodManager.SHOW_IMPLICIT);

                        ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);



                    }
                });

                rb_A = (RadioButton)convertView.findViewById(R.id.radio_A);
                rb_B = (RadioButton)convertView.findViewById(R.id.radio_B);
                rb_AB = (RadioButton)convertView.findViewById(R.id.radio_A_B);

                rb_A.setOnClickListener(Measure_New.this);
                rb_B.setOnClickListener(Measure_New.this);
                rb_AB.setOnClickListener(Measure_New.this); 




             view[position] = convertView; 

        }

         else if(position==n+1){

                convertView=mInflater.inflate( R.layout.details_continue_btn, null);
                convertView.findViewById(R.id.btn_Continue).setOnClickListener(Measure_New.this);
                convertView.findViewById(R.id.btn_exit_restart).setOnClickListener(Measure_New.this);

                view[position] = convertView;
           }
        else{   


                     if(optn_checkd==1){

                         setDatabase();

                     convertView = mInflater.inflate(R.layout.a_xml, null);
                     txt_A_ft_mtr=(TextView)convertView.findViewById(R.id.textView_A_ft_mtr);
                     txt_A_inch_cm=(TextView)convertView.findViewById(R.id.TextView_A_inch_cm);
                     if(Settings.metric_count ==1){
                         txt_A_ft_mtr.setText(""+"A(m.)");
                         txt_A_inch_cm.setText(""+"A(cm.)");
                     }


                     holderAB.text = (TextView) convertView.findViewById(R.id.num_txt);
                     holderAB.text.setText(""+(position));



                     edit_a_ft=(EditText) convertView.findViewById(R.id.editText_A_ft);
                     edit_a_inch=(EditText) convertView.findViewById(R.id.editText_A_inch);

                     if(position<=n){
                     textChangeListenerForFeet(edit_a_ft,position,al_edit_A_ft);
                     textChangeListenerForInch(edit_a_inch,edit_a_ft,position,al_edit_A_inch);
                     }

                     System.out.println("in else value of position before crashing is"+position+"  "+(position-1)+"  "+ n);
                     if(position<=n){
                     ob[position-1]=(RadioButton)convertView.findViewById(R.id.radio_Obstruction_a);
                     ob[position-1].setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            if(radio__ob_flag[position-1]==true){
                                ob[position-1].setButtonDrawable(R.drawable.redioon);
                                obstruction/*[position-1]*/="Y";

                                radio__ob_flag[position-1]=false;
                            }
                            else{
                                ob[position-1].setButtonDrawable(R.drawable.rediooff);
                                radio__ob_flag[position-1]=true;
                                obstruction/*[position-1]*/="N";

                            }
                             try{
                                    al_ob_a.add(position-1,obstruction/*[position-1]*/);

                                        al_ob_a.remove(position);


                                    }catch(Exception e){

                                    }

                            System.out.println("wooooow here i am ob"+al_ob_a);
                        }
                    });
                     }

                     if(position<=n){
                     ra[position-1]=(RadioButton)convertView.findViewById(R.id.radio_Raisedwall_a);
                     ra[position-1].setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub


                            if(radio__ra_flag[position-1]==true){
                                ra[position-1].setButtonDrawable(R.drawable.redioon);

                                radio__ra_flag[position-1]=false;
                                obstruction/*[position-1]*/="Y";

                            }
                            else{
                                ra[position-1].setButtonDrawable(R.drawable.rediooff);
                                radio__ra_flag[position-1]=true;
                                obstruction/*[position-1]*/="N";

                            }

                             try{
                                    al_ra_a.add(position-1,obstruction/*[position-1]*/);

                                    al_ra_a.remove(position);

                                    }catch(Exception e){

                                    }


                            System.out.println("wooooow here i am ra "+al_ra_a);
                        }
                    });
                     }

                     if(getttingFromDbForMeasure()==true){
                    if(position<=n){

                       retainingInput(al_edit_A_ft,position,edit_a_ft);
                       retainingInput(al_edit_A_inch,position,edit_a_inch);
                       retainingInputForRadio( al_ob_a,position,ob);
                       retainingInputForRadio(al_ra_a ,position,ra);


                    }
                     }

                     }
4

1 に答える 1

0

まず、アダプタgetView()でconvertViewを利用する必要があります。これにより、ビューホルダーを使用できるようになります。現在、viewHolderに値を割り当てるだけで、タグとして設定したり、値を取得したりすることはできません(冗長なfindViewById呼び出しを回避するため)。

RomainGuyからこのGoogleI/ Oビデオをチェックアウトし、そのセッションスライドからコードもチェックアウトしてください。

于 2012-07-28T10:25:32.060 に答える