虽然调用了getCount,但是没有调用ArrayAdapter getview

时间:2016-02-23 12:09:56

标签: android android-arrayadapter getview

ArrayAdapter getView未被调用,而getCount返回listsize。我在使用列表上的原始列表项设置适配器之前已应用setAdapter(null)来设置适配器但它无法正常工作。

同样尝试BaseAdapter,但仍然没有运气

我尝试的代码是 -

public  PrintLabelAdapter(Context context, int layoutResourceId, ArrayList<String> data) {
super(context, layoutResourceId, data);
       this.layoutResourceId = layoutResourceId;
       this.context = context;
       this.data = data;
       //Log.d("sublistcount", "sublistcount" +data.size());
   }

   @Override
   public int getCount() {

       Log.d("getcount", "getcount" + data.size());
       return data.size();
   }

   @Override
   public View getView(final int position, View convertView, ViewGroup parent) {
       View row = convertView;
       WeatherHolder holder = null;
      // db=new DatabaseHandler( context);

       Log.d("getcount", "getcount in getview" + data.size());
       final String weather;
       if (row == null) {

           Log.d("getcount", "getcount in getviewin row i");

           LayoutInflater inflater = ((Activity) context).getLayoutInflater();
           row = inflater.inflate(layoutResourceId, parent, false);

           holder = new WeatherHolder();
           // holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
           holder.txt = (TextView) row.findViewById(R.id.txt);

           holder.chk = (CheckBox) row.findViewById(R.id.chk);

           row.setTag(holder);
       } else {

           Log.d("getcount", "getcount in getviewin row i111");
           holder = (WeatherHolder) row.getTag();
       }

       weather = data.get(position);

       holder.txt.setText(weather);
       // holder.imgIcon.setImageResource(weather.icon);
       final WeatherHolder finalHolder = holder;
       holder.chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

               if(isChecked){
                   finalHolder.chk.setButtonDrawable(R.mipmap.checked);

                   //db.updateMovingDay(weather.getTitle(),1);
               }
               else
               {
                  // db.updateMovingDay(weather.getTitle(),0);
                   finalHolder.chk.setButtonDrawable(R.mipmap.uncheck);

               }

           }
       });

       return row;
   }

   static class WeatherHolder {
       ImageView imgIcon;
       TextView txt;
       CheckBox chk;
   }

}

这是我的setAdapter代码 -

PrintLabelAdapter  labeladapternew = new PrintLabelAdapter(mContext,R.layout.labeitem, fine.get(i));
list4.setAdapter(labeladapternew);
labeladapternew.notifyDataSetChanged();
list4.invalidateViews();

如果我做错了,请告诉我。

修改

public class PrintLabelScreen  extends Activity {
    // http://developers.itextpdf.com/itext-java

    Context mContext;
    ImageView head, img_back, icon;
    TextView centertxt;
    ImageView search, print, inbox, home, fav;
    ListView list1, list2, list3, list4;
    String label;
    TextView text1, texts1, text2, texts2, text3, texts3, text4, texts4;

    String priorty;
    int i1;

    ArrayList aList;
    Button fragilebtn, fragilebtn1, fragilebtn2, fragilebtn3;
    List<String> sublist = null;
    List<String> sublist1 = null;
    String fragile;

    Button next, prev;

    int count = 0;
    PrintLabelAdapter     labeladapter;
    int prevcount = 0;
    Map<Integer, ArrayList<String>> m1 = new HashMap<Integer, ArrayList<String>>();
//    Map<Integer,List<Integer>> m2 = new HashMap<Integer,List<Integer>>();
//
List<ArrayList<User>> usize=null;
    List<ArrayList<String>> favlist=null;
    AbstractViewRenderer page = null;
    AbstractViewRenderer page1 = null;
    AbstractViewRenderer page2 = null;
    AbstractViewRenderer page3 = null;
    LinearLayout linear1, linear2;
    ProgressBar progressBar1;
DatabaseHandler db;
    ArrayList finalList = new ArrayList<String>();
    List<List<ArrayList<String>>> finallist;
 int count1=0;
RelativeLayout lastrel;
    //PdfDocument doc
PdfDocument doc=null;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.printlabel);

        mContext = PrintLabelScreen.this;
       db=new DatabaseHandler(mContext);

        centertxt = (TextView) findViewById(R.id.centertxt);

        centertxt.setText("Print Labels");
        icon.setVisibility(View.GONE);
        img_back.setVisibility(View.GONE);
        head.setVisibility(View.GONE);
        search.setVisibility(View.GONE);
        fav.setVisibility(View.GONE);
        home.setVisibility(View.VISIBLE);
        print.setVisibility(View.VISIBLE);
        inbox.setVisibility(View.VISIBLE);
        text4 = (TextView) findViewById(R.id.text4);
        texts4 = (TextView) findViewById(R.id.texts4);



        Log.d("text", "text" + fragile);
        texts1.setText("UNPACKING PRIORITY:" + priorty);
        texts2.setText("UNPACKING PRIORITY:" + priorty);
        texts3.setText("UNPACKING PRIORITY:" + priorty);
        texts4.setText("UNPACKING PRIORITY:" + priorty);

        text1.setText(label);
        text2.setText(label);
        text3.setText(label);
        text4.setText(label);


        aList = new ArrayList(Arrays.asList(text.split(",")));



       if(aList.size()>40)
       {
        lastrel.setVisibility(View.VISIBLE);
       }

        Log.d("FFFFFFF", "FFFFFF" +  aList.size());




        if (!aList.get(0).equals("")) {
            i1 = (int) Math.ceil(aList.size() / 10.0);
        }

        sublist = new ArrayList<String>();


        int x = 0;
        for (int p = 0; p < i1; p++) {


            //Log.d("listiss", "listiss" +p);
            if (aList.size() >= (x + 10)) {
                sublist = new ArrayList<String>(aList.subList(x, x + 10));
                x += 10;
            } else {
                sublist = new ArrayList<String>(aList.subList(x, aList.size()));


            }




            finalList.add(sublist );

            Log.d("finallist", "finallist" +     finalList.size());


            prevcount=sublist.size();
    //db.addLabelItem(p, (ArrayList<String>) sublist);


          //  addLabelItem(String id, ArrayList < String > labellist)



            m1.put(p,(ArrayList<String>) sublist);


            if (fragile.equalsIgnoreCase("Y")) {
                fragilebtn.setVisibility(View.VISIBLE);
                fragile = "Y";

            } else {
                fragilebtn.setVisibility(View.GONE);
                fragile = "N";

            }


            if (aList.size() != 0) {
                if (p == 0) {

                    if (fragile.equalsIgnoreCase("Y")) {
                        fragilebtn.setVisibility(View.VISIBLE);
                        fragile = "Y";

                    } else {
                        fragilebtn.setVisibility(View.GONE);
                        fragile = "N";

                    }
       labeladapter = new PrintLabelAdapter(this,R.layout.labeitem,
                            (ArrayList) m1.get(p));
                    list1.setAdapter(labeladapter);


                } else if (p == 1) {
                    if (fragile.equalsIgnoreCase("Y")) {
                        fragilebtn1.setVisibility(View.VISIBLE);
                        fragile = "Y";


                    } else {
                        fragilebtn1.setVisibility(View.GONE);
                        fragile = "N";

                    }


             labeladapter = new PrintLabelAdapter(this,R.layout.labeitem,
                            (ArrayList) m1.get(p));
                    list2.setAdapter(labeladapter);

                } else if (p == 2) {
                    if (fragile.equalsIgnoreCase("Y")) {
                        fragilebtn2.setVisibility(View.VISIBLE);
                        fragile = "Y";

                    } else {
                        fragilebtn2.setVisibility(View.GONE);
                        fragile = "N";
                    }


             labeladapter = new PrintLabelAdapter(this,R.layout.labeitem,
                            (ArrayList) m1.get(p));
                    list3.setAdapter(labeladapter);

                } else if (p == 3) {


                    if (fragile.equalsIgnoreCase("Y")) {
                        fragilebtn3.setVisibility(View.VISIBLE);
                        fragile = "Y";

                    } else {
                        fragilebtn3.setVisibility(View.GONE);
                        fragile = "N";

                    }

        labeladapter = new PrintLabelAdapter(this,R.layout.labeitem,
                            (ArrayList) m1.get(p));
                    list4.setAdapter(labeladapter);

                }


            }


        }



        finallist=chopped(finalList,4);

        Log.d("FFFFFFF", "FFFFFF" +    finallist.size());

       // Log.d("Array", "Array 1" +finallist.size());

        inbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                int x = 0;


             try {
                 for (int i = 0; i < finallist.size(); i++) {

                     final int finalI = i;
                     page = new AbstractViewRenderer(mContext, R.layout.printlabel1) {
                         private String _text;

                         public void setText(String text) {



                         }

                         @Override
                         protected void initView(View view) {
                             // TextView tv_hello = (TextView)view.findViewById(R.id.tv_hello);
                             //PrintLabelAdapter labeladapter = null; //tv_hello.setText(_text);


                             favlist = finallist.get(finalI);

                             for (int j = 0; j < favlist.size(); j++) {


                                 if (j == 0) {

                                     labeladapter = new PrintLabelAdapter(mContext,R.layout.labitem,
                                             favlist.get(0));

                                     list1 = (ListView) view.findViewById(R.id.list1);
                                     list1.setAdapter(labeladapter);
                                     labeladapter.notifyDataSetChanged();
                                     text1 = (TextView) view.findViewById(R.id.text1);
                                     texts1 = (TextView) view.findViewById(R.id.texts1);

                                     fragilebtn = (Button) view.findViewById(R.id.fragilebtn);


                                     texts1.setText("UNPACKING PRIORITY:" + priorty);
                                     text1.setText(label);

                                     try {

                                         if (fragile.equalsIgnoreCase("Y")) {

                                             fragilebtn.setVisibility(View.VISIBLE);
                                         }
                                     } catch (Exception e) {
                                         e.printStackTrace();
                                     }

                                 }


                                 if (j == 1) {
                                     labeladapter = new PrintLabelAdapter(mContext,R.layout.labitem,
                                             favlist.get(1));
                                     //Log.d("listiss","listiss"+slist2.size());

                                     list2 = (ListView) view.findViewById(R.id.list2);
                                     list2.setAdapter(labeladapter);
                                     labeladapter.notifyDataSetChanged();
                                     text2 = (TextView) view.findViewById(R.id.text2);
                                     texts2 = (TextView) view.findViewById(R.id.texts2);
                                     fragilebtn1 = (Button) view.findViewById(R.id.fragilebtn1);


                                     texts2.setText("UNPACKING PRIORITY:" + priorty);
                                     text2.setText(label);

                                     try

                                     {
                                         if (fragile.equalsIgnoreCase("Y")) {

                                             fragilebtn1.setVisibility(View.VISIBLE);
                                         }
                                     } catch (Exception e)

                                     {
                                         e.printStackTrace();
                                         ;
                                     }


                                 }


                                 if (j == 2)

                                 {

                                     labeladapter = new PrintLabelAdapter(mContext,R.layout.labitem,
                                             favlist.get(2));


                                     list3 = (ListView) view.findViewById(R.id.list3);
                                     list3.setAdapter(labeladapter);
                                     labeladapter.notifyDataSetChanged();
                                     text3 = (TextView) view.findViewById(R.id.text3);
                                     texts3 = (TextView) view.findViewById(R.id.texts3);
                                     fragilebtn2 = (Button) view.findViewById(R.id.fragilebtn2);

                                     texts3.setText("UNPACKING PRIORITY:" + priorty);
                                     text3.setText(label);
                                     try {

                                         if (fragile.equalsIgnoreCase("Y")) {

                                             fragilebtn2.setVisibility(View.VISIBLE);
                                         }
                                     } catch (Exception e) {
                                         e.printStackTrace();
                                     }


                                 }


                                 if (j == 3) {

                                     labeladapter = new PrintLabelAdapter(mContext,R.layout.labitem,
                                             favlist.get(3));


                                     list4 = (ListView) view.findViewById(R.id.list4);
                                     list4.setAdapter(labeladapter);
                                     labeladapter.notifyDataSetChanged();
                                     text4 = (TextView) view.findViewById(R.id.text4);
                                     texts4 = (TextView) view.findViewById(R.id.texts4);
                                     fragilebtn3 = (Button) view.findViewById(R.id.fragilebtn3);
                                     texts4.setText("UNPACKING PRIORITY:" + priorty);
                                     text4.setText(label);

                                     try {
                                         if (fragile.equalsIgnoreCase("Y")) {

                                             fragilebtn3.setVisibility(View.VISIBLE);
                                         }
                                     } catch (Exception e) {
                                         e.printStackTrace();
                                     }

                                 }
                             }

                         }


                         //  }


                     };


                     page.setReuseBitmap(true);



                     doc.addPage(page);
                 }





                 doc.setRenderWidth(2800);
                 doc.setRenderHeight(3900);
                 doc.setOrientation(PdfDocument.A4_MODE.PORTRAIT);
                 //   doc.setProgressTitle(R.string.gen_please_wait);
                 //  doc.setProgressMessage(R.string.gen_pdf_file);
                 doc.setFileName(label);

                 doc.setInflateOnMainThread(false);
                 doc.setListener(new PdfDocument.Callback() {
                     @Override
                     public void onComplete(File file) {
                         Log.i(PdfDocument.TAG_PDF_MY_XML, "Complete" + file.getAbsolutePath());

                         {

                             String[] mailto = {""};
                             Uri uri = Uri.fromFile(file.getAbsoluteFile());
                             Intent emailIntent = new Intent(Intent.ACTION_SEND);
                             emailIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                             emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Label for " + label);
                             emailIntent.putExtra(Intent.EXTRA_TEXT, "By android device");
                             emailIntent.setType("application/pdf");
                             emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                             startActivity(Intent.createChooser(emailIntent, "Send email using:"));
                         }
                     }

                     @Override
                     public void onError() {
                         Log.i(PdfDocument.TAG_PDF_MY_XML, "Error");
                     }
                 });

               try {
                   doc.createPdf(mContext);
               }
               catch(Exception e)
               {
                   e.printStackTrace();
               }



             }
             catch(Exception e)
             {
                 e.printStackTrace();
             }





            }
        });

        home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(new Intent(PrintLabelScreen.this, MainScreen.class));


            }
        });

        next.setOnClickListener(new View.OnClickListener() {
            ProgressDialog mProgressDialog;

            @Override
            public void onClick(View v) {

                //mProgressDialog = ProgressDialog.show(mContext, "", "Loading...");





                if(count1>=0&&count1<finallist.size()-1)


                {
                    count1++;
                    for (int i = 0; i < finallist.size(); i++) {

                        if (i == count1) {

                            favlist = finallist.get(i);



                            list1.setAdapter(null);
                           list2.setAdapter(null);
                          list3.setAdapter(null);
                          list4.setAdapter(null);
                         //labeladapter.notifyDataSetChanged();

                        new BackgroundProcess().execute(favlist);



                     }

                    }

                }
                }
        });

        prev.setOnClickListener(new View.OnClickListener() {

           // ProgressDialog mProgressDialog;

            @Override
            public void onClick(View v) {

            //   Log.d("sublistsize","sublistsize"+    prevcount);


                Log.d("count1","count2"+count1);

                Log.d("count1","count2"+finallist.size());
                Log.d("prevcount"," prevcount"+count1);
                if(count1>0 && count1<=finallist.size()) {
                    count1--;

                 for (int i = 0; i < finallist.size(); i++) {

                        if (i == count1) {


                            favlist=finallist.get(i);
                            list1.setAdapter(null);
                            list2.setAdapter(null);
                            list3.setAdapter(null);
                            list4.setAdapter(null);
                            //labeladapter.notifyDataSetChanged();
                            new BackgroundProcess().execute(favlist);
                        }
                    }
              }


            }
        });


    }

    class BackgroundProcess extends AsyncTask<List<ArrayList<String>>, String, String> {
        private ProgressDialog progress;
        List<ArrayList<String>> fine=null;

        Set<Integer> m1Key;
        ProgressDialog dialog = new ProgressDialog(PrintLabelScreen.this);

        @Override
        protected void onPreExecute() {

            dialog.setMessage("Loading...");
            //show dialog
            dialog.show();

            super.onPreExecute();



        }


        @Override
        protected String doInBackground(List<ArrayList<String>>... params) {



try {
fine= params[0];
    Log.d("finesize", "finesize" +    fine.size());

}
catch(Exception e)
{
    e.printStackTrace();
}
            //m1Key = m1.keySet();

            if (fine.size()!= 0) {
                return "1";
            }
            else {
                return "0";
            }
        }



        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if(dialog != null && dialog.isShowing()){
                dialog.dismiss();
            }





            if (result.equalsIgnoreCase("1")) {


                for (int i = 0; i < fine.size(); i++) {



                    if (i == 0) {

                        if (fine.get(i).size() != 0) {


                            if (fragile.equalsIgnoreCase("Y")) {
                                fragilebtn.setVisibility(View.VISIBLE);
                                fragile = "Y";

                            } else {
                                fragilebtn.setVisibility(View.GONE);
                                fragile = "N";

                            }

                         //   Log.d("sublistcount", "sublistcount" +fine.get(i));
                            PrintLabelAdapter  labeladapternew  = new PrintLabelAdapter(mContext,R.layout.labeitem,
                                    fine.get(i));


                            list1.setAdapter(labeladapternew);
                            labeladapternew.notifyDataSetChanged();
list1.invalidateViews();

                        }
                    }
         if (i == 1) {


                        if (fine.get(i).size() != 0) {


                            if (fragile.equalsIgnoreCase("Y")) {
                                fragilebtn1.setVisibility(View.VISIBLE);
                                fragile = "Y";


                            } else {
                                fragilebtn1.setVisibility(View.GONE);
                                fragile = "N";

                            }


                            PrintLabelAdapter   labeladapternew  = new PrintLabelAdapter(mContext,R.layout.labeitem,
                                    fine.get(i));

                            //list2.setAdapter(null);
                            list2.setAdapter(labeladapternew);
                            labeladapternew.notifyDataSetChanged();

                            list2.invalidateViews();



                        }

                    }
          if (i == 2) {


                        if (fine.get(i).size() != 0) {



                            if (fragile.equalsIgnoreCase("Y")) {
                                fragilebtn2.setVisibility(View.VISIBLE);
                                fragile = "Y";

                            } else {
                                fragilebtn2.setVisibility(View.GONE);
                                fragile = "N";
                            }



                         //   Log.d("sublistcount", "sublistcount" +fine.get(i));
                            PrintLabelAdapter   labeladapternew = new PrintLabelAdapter(mContext,R.layout.labeitem,
                                    fine.get(i));
                          //  list3.setAdapter(null);

                            list3.setAdapter(labeladapternew);
                            labeladapternew.notifyDataSetChanged();

                            list3.invalidateViews();
                        }
                    }


           if (i == 3) {

                        if (fine.get(i).size() != 0) {


                            if (fragile.equalsIgnoreCase("Y")) {
                                fragilebtn3.setVisibility(View.VISIBLE);
                                fragile = "Y";

                            } else {
                                fragilebtn3.setVisibility(View.GONE);
                                fragile = "N";

                            }

                            //list4.setAdapter(null);

                        //  Log.d("sublistcount", "sublistcount" +fine.get(i));
                            PrintLabelAdapter  labeladapternew = new PrintLabelAdapter(mContext,R.layout.labeitem,
                                    fine.get(i));
                            list4.setAdapter(labeladapternew);

                            labeladapternew.notifyDataSetChanged();
                            list4.invalidateViews();



                        }

                    }




                }
            }

        }
    }

    // chops a list into non-view sublists of length L
    static <T> List<List<T>> chopped(List<T> list, final int L) {
        List<List<T>> parts = new ArrayList<List<T>>();
        final int N = list.size();
        for (int i = 0; i < N; i += L) {
            parts.add(new ArrayList<T>(
                            list.subList(i, Math.min(N, i + L)))
            );
        }
        return parts;
    }


}

修改

它第一次工作,当我按下底部的按钮和下一个按钮时也可以工作,但是在我发送邮件后,又回来了,它不那么令人耳目一新

3 个答案:

答案 0 :(得分:0)

  

getView未被调用,而getCount返回listsize

查看你的代码一切都很好。但是,只是为了让您意识到,如果ListView的可见性将其根视图设置为GONE,也会发生这种情况。

答案 1 :(得分:0)

试试这个

public  PrintLabelAdapter(Context context, int layoutResourceId,ArrayList<String> data) {
     super();
   this.layoutResourceId = layoutResourceId;
   this.context = context;
   this.data = data;
   //Log.d("sublistcount", "sublistcount" +data.size());
}

    @Override
public int getCount() {

   Log.d("getcount", "getcount" + data.size());
   return data.size();
}

 @Override
public View getView(final int position, View convertView, ViewGroup parent) {
   View row = convertView;
   WeatherHolder holder = null;
  // db=new DatabaseHandler( context);

   Log.d("getcount", "getcount in getview" + data.size());
   final String weather;
   if (row == null) {

       Log.d("getcount", "getcount in getviewin row i");

       LayoutInflater inflater = ((Activity) context).getLayoutInflater();
       row = inflater.inflate(layoutResourceId, parent, false);

       holder = new WeatherHolder();
       // holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
       holder.txt = (TextView) row.findViewById(R.id.txt);

       holder.chk = (CheckBox) row.findViewById(R.id.chk);

       row.setTag(holder);
   } else {

       Log.d("getcount", "getcount in getviewin row i111");
       holder = (WeatherHolder) row.getTag();
   }

   weather = data.get(position);

   holder.txt.setText(weather);
   // holder.imgIcon.setImageResource(weather.icon);
   final WeatherHolder finalHolder = holder;
   holder.chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

           if(isChecked){
               finalHolder.chk.setButtonDrawable(R.mipmap.checked);

               //db.updateMovingDay(weather.getTitle(),1);
           }
           else
           {
              // db.updateMovingDay(weather.getTitle(),0);
               finalHolder.chk.setButtonDrawable(R.mipmap.uncheck);

           }

       }
   });

   return row;
 }

 static class WeatherHolder {
   ImageView imgIcon;
   TextView txt;
   CheckBox chk;
  }

 }

注意我在适配器扩展baseadapter

时更改了super()语句

希望它有助于感谢。请参阅https://androidruler.wordpress.com/2016/02/21/android-custom-listview-example/

答案 2 :(得分:0)

这是我的XML

主要布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.lokesh.myapplication.TestClass">


<ListView
    android:id="@+id/lv_test"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</ListView>
</LinearLayout>

item_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<CheckBox
    android:id="@+id/chk"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</LinearLayout>

这是主要的课程。

public class TestClass extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gridview_main);


    ListView ls = (ListView)findViewById(R.id.lv_test);
    ArrayList<String> hit = new ArrayList<>();
    hit.add("DONE");
    hit.add("DONE");
    hit.add("DONE");
    hit.add("DONE");
    hit.add("DONE");
    hit.add("DONE");
    hit.add("DONE");
    PrintLabelAdapter adapter = new          
    PrintLabelAdapter(this,R.layout.item_list,hit );
    ls.setAdapter(adapter);

}
}

这是你的适配器没有改变

 public class PrintLabelAdapter extends ArrayAdapter {


int layoutResourceId;
Context context;
ArrayList<String> data;

public PrintLabelAdapter(Context context, int layoutResourceId, ArrayList<String> data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
    //Log.d("sublistcount", "sublistcount" +data.size());
}

@Override
public int getCount() {

    Log.d("getcount", "getcount" + data.size());
    return data.size();
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View row = convertView;
    WeatherHolder holder = null;
    // db=new DatabaseHandler( context);

    Log.d("getcount", "getcount in getview" + data.size());
    final String weather;
    if (row == null) {

        Log.d("getcount", "getcount in getviewin row i");

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new WeatherHolder();
        // holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
        holder.txt = (TextView) row.findViewById(R.id.txt);

        holder.chk = (CheckBox) row.findViewById(R.id.chk);

        row.setTag(holder);
    } else {

        Log.d("getcount", "getcount in getviewin row i111");
        holder = (WeatherHolder) row.getTag();
    }

    weather = data.get(position);

    holder.txt.setText(weather);
    // holder.imgIcon.setImageResource(weather.icon);
    final WeatherHolder finalHolder = holder;
    holder.chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {
                //finalHolder.chk.setButtonDrawable(R.mipmap.checked);

                //db.updateMovingDay(weather.getTitle(),1);
            } else {
                // db.updateMovingDay(weather.getTitle(),0);
                //finalHolder.chk.setButtonDrawable(R.mipmap.uncheck);

            }

        }
    });

    return row;
}

static class WeatherHolder {
    TextView txt;
    CheckBox chk;
  }
 }