ListView控件过滤的错误 [英] listView filter mistake

查看:147
本文介绍了ListView控件过滤的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共类testListFilter扩展ListActivity {
/ **当第一次创建活动调用。 * /
ArrayList的< GlycaemicIndexItem>项目;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    GlycaemicIndexItem GL =新GlycaemicIndexItem();
    gl.setName(王);
    gl.setimagepath(DFD);
    GlycaemicIndexItem G2 =新GlycaemicIndexItem();
    g2.setName(「李先生」);
    g2.setimagepath(DFD);
    GlycaemicIndexItem G3 =新GlycaemicIndexItem();
    g3.setName(嘀);
    g3.setimagepath(DFD);
    GlycaemicIndexItem G4 =新GlycaemicIndexItem();
    g4.setName(di34);
    g4.setimagepath(DFD);
    GlycaemicIndexItem G5 =新GlycaemicIndexItem();
    g5.setName(ai34);
    g5.setimagepath(DFD);
    GlycaemicIndexItem G6 =新GlycaemicIndexItem();
    g6.setName(香鱼);
    g6.setimagepath(DFD);    items.add(GL);
    items.add(G2);
    items.add(G3);
    items.add(G4);
    items.add(G5);
    items.add(G6);
    GlycaemicIndexItemAdapter GI =新GlycaemicIndexItemAdapter(这一点,1项);
    getListView()setAdapter(GI)。
   // setListAdapter(GI);
}
}
   公共类GlycaemicIndexItem {
  公共字符串名称;
  公共字符串的ImagePath;
  公共字符串的getName(){
    返回名称;
    }
      公共无效setname可以(字符串名称){
   this.name =名称;
        }       公共字符串getimagepath(){
    返回的ImagePath;
  }
    公共无效setimagepath(字符串的ImagePath){
   this.imagepath =的ImagePath;
    }
 }

和GlycaemicIndexItemAdapter我从<一个名为href=\"http://stackoverflow.com/questions/2519317/how-tto-write-a-custom-filter-for-listview-with-arrayadapter\">How写一个自定义过滤器与ArrayAdapter ListView的,但是当我运行这个程序,它显示:

 
十月3日至23日:52:03.903:ERROR / AndroidRuntime(971):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.test.testListFilter / com.test.testListFilter.testListFilter}:显示java.lang.NullPointerException
十月3日至23日:52:03.903:ERROR / AndroidRuntime(971):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
十月3日至23日:52:03.903:ERROR / AndroidRuntime(971):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
十月3日至23日:52:03.903:ERROR / AndroidRuntime(971):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
十月3日至23日:52:03.903:ERROR / AndroidRuntime(971):在com.test.testListFilter.testListFilter.onCreate(testListFilter.java:33)

编辑:<一href=\"http://stackoverflow.com/questions/2519317/how-to-write-a-custom-filter-for-listview-with-arrayadapter/5381365#5381365\">How写与ArrayAdapter的ListView自定义过滤器是很好的,如果需要你可以看到这个链接


解决方案

 项目=新的ArrayList&LT; GlycaemicIndexItem&GT;();

在的onCreate的第一行添加此。

感谢。

public class testListFilter extends ListActivity {
/** Called when the activity is first created. */
ArrayList<GlycaemicIndexItem> items;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GlycaemicIndexItem gl= new GlycaemicIndexItem();
    gl.setName("wang");
    gl.setimagepath("dfd");
    GlycaemicIndexItem g2= new GlycaemicIndexItem();
    g2.setName("li");
    g2.setimagepath("dfd");
    GlycaemicIndexItem g3= new GlycaemicIndexItem();
    g3.setName("di");
    g3.setimagepath("dfd");
    GlycaemicIndexItem g4= new GlycaemicIndexItem();
    g4.setName("di34");
    g4.setimagepath("dfd");
    GlycaemicIndexItem g5= new GlycaemicIndexItem();
    g5.setName("ai34");
    g5.setimagepath("dfd");
    GlycaemicIndexItem g6= new GlycaemicIndexItem();
    g6.setName("ayu");
    g6.setimagepath("dfd");

    items.add(gl);
    items.add(g2);
    items.add(g3);
    items.add(g4);
    items.add(g5);
    items.add(g6);
    GlycaemicIndexItemAdapter Gi=new GlycaemicIndexItemAdapter(this,1,items);
    getListView().setAdapter(Gi);
   // setListAdapter(Gi);
}
}


   public class GlycaemicIndexItem {
  public String name;
  public String imagepath;
  public String  getName(){
    return name;
    }
      public  void setName( String  name){
   this.name=name;
        }

       public String  getimagepath(){
    return imagepath;
  }
    public  void setimagepath(String  imagepath){
   this.imagepath=imagepath;
    }
 }

and GlycaemicIndexItemAdapter i called from How to write a custom filter for ListView with ArrayAdapter, but when i run this app, it is show:


03-23 10:52:03.903: ERROR/AndroidRuntime(971): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.testListFilter/com.test.testListFilter.testListFilter}: java.lang.NullPointerException


03-23 10:52:03.903: ERROR/AndroidRuntime(971):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)


03-23 10:52:03.903: ERROR/AndroidRuntime(971):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)


03-23 10:52:03.903: ERROR/AndroidRuntime(971):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)


03-23 10:52:03.903: ERROR/AndroidRuntime(971):     at com.test.testListFilter.testListFilter.onCreate(testListFilter.java:33)

edit: How to write a custom filter for ListView with ArrayAdapter is very well, if you need you can see this link

解决方案

items=new ArrayList<GlycaemicIndexItem>();

add this in first line of onCreate.

Thanks.

这篇关于ListView控件过滤的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆