android listview数组适配器app force关闭

时间:2014-01-27 10:14:37

标签: android listview

您好我正在使用android。我通过自己的自定义创建了一个导航抽屉应用程序。我将自己的页面添加到每个菜单视图中,这是一个listview数组适配器。但是当单击菜单项时它看起来强制关闭。我使用了片段扩展。但它因某种原因被迫关闭,我找不到错误请帮助我,谢谢。 这是我的代码

  SentTaskFragment.java


public class SentTaskFragment extends Fragment {
     private ListView listView2;
     public SentTaskFragment(){}

     public View onCreateView(LayoutInflater inflater1, ViewGroup container,
                     Bundle savedInstanceState) {
     View rootView1 = inflater1.inflate(R.layout.fragment_photos, container, false);
     SentTask weather_data2[] = new SentTask[]
                    {
                      new SentTask(R.drawable.ic_launcher, "Task1","this is a task",R.drawable.green),
                        new SentTask(R.drawable.ic_launcher, "Task2","this is a task",R.drawable.red),
                        new SentTask(R.drawable.ic_launcher, "Task3","this is a task",R.drawable.red),
                        new SentTask(R.drawable.ic_launcher, "Task4","this is a task",R.drawable.green),
                        new SentTask(R.drawable.ic_launcher, "Task5","this is a task",R.drawable.red)
                    };
           SentTaskAdapter adapter = new SentTaskAdapter(getActivity(), 
                    R.layout.listview_item_row_sent, weather_data2);


               listView2 = (ListView)rootView1.findViewById(R.id.listView2);

              View header = (View)getActivity().getLayoutInflater().inflate(R.layout.listview_header_row_sent, null);
              listView2.addHeaderView(header);

              listView2.setAdapter(adapter);
              return rootView1;

    }



      SentTask.java




    public class SentTask {
          public int icon2,imgstatus2;
          public String title2,text2;
          public SentTask(){
          super();
       }

          public SentTask(int icon2, String title2,String text2,int imgstatus2) {
         super();
         this.icon2 = icon2;
         this.title2 = title2;
         this.text2=text2;
         this.imgstatus2= imgstatus2;
    }
 }


       SentTaskAdapter.java



     public class SentTaskAdapter extends ArrayAdapter<SentTask>{

     Context context2; 
     int layoutResourceId2;    
     SentTask[] data2 = null;

         public SentTaskAdapter(Context context2, int layoutResourceId2, SentTask[] data2) {
         super(context2, layoutResourceId2, data2);
         this.layoutResourceId2 = layoutResourceId2;
         this.context2 = context2;
         this.data2 = data2;
      }

      @Override
     public View getView(int position, View convertView2, ViewGroup parent) {
         View row2 = convertView2;
         WeatherHolder2 holder2 = null;

         if(row2 == null)
        {
             LayoutInflater inflater2 = ((Activity)context2).getLayoutInflater();
            row2 = inflater2.inflate(layoutResourceId2, parent, false);

            holder2 = new WeatherHolder2();
            holder2.imgIcon2 = (ImageView)row2.findViewById(R.id.imgIcon2);
           holder2.txtTitle2 = (TextView)row2.findViewById(R.id.txtTitle2);
           holder2.text2 = (TextView)row2.findViewById(R.id.textview12);
           holder2.imgstatus2 = (ImageView)row2.findViewById(R.id.status2);
           row2.setTag(holder2);
        }
        else
        {
              holder2 = (WeatherHolder2)row2.getTag();
        }

          SentTask weather = data2[position];
          holder2.txtTitle2.setText(weather.title2);
          holder2.imgIcon2.setImageResource(weather.icon2);
          holder2.text2.setText(weather.text2);
          holder2.imgstatus2.setImageResource(weather.imgstatus2);


         return row2;
    }

     static class WeatherHolder2
     {
        ImageView imgIcon2,imgstatus2;
        TextView txtTitle2,text2;
    }
  }

0 个答案:

没有答案