过滤要在图像适配器中使用的arraylist

时间:2012-07-31 11:52:14

标签: android image listview filter adapter

所以我需要在ImageAdapter 2个不同的布局中使用ListView。我将它用于第一个,然后想要过滤数组,将这些值放在另一个数组中我用于第二个列表视图。

我的图像适配器

package com.weinco.list;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.androidquery.AQuery;
import com.weinco.R;
import com.weinco.fragments.StandorteFragment;
import com.weinco.webservice.entity.Standort;

import com.weinco.webservice.entity.Standorts;

public class LocationMenuAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private AQuery aQuery;
private Standorts standorts;
private Standort standort;
private StandorteFragment standorteFragment;

public LocationMenuAdapter(StandorteFragment standorteFragment, Standorts standorts) {

    this.standorteFragment = standorteFragment;
    this.standorts = standorts;
    this.aQuery = standorteFragment.aQuery;
    mInflater = LayoutInflater.from(standorteFragment.getActivity());

}

public int getCount() {
    return standorts.size();
}

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

public long getItemId(int position) {
    return position;
}

public Standort getStandort(int i) {
    return standorts.get(i);
}

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

    ListContent holder = null;

    Standort standort = getStandort(position);

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.listviewinflate, null);

        holder = new ListContent();
        holder.text = (TextView) convertView.findViewById(R.id.TextView01);

        convertView.setTag(holder);
    } else {
        holder = (ListContent) convertView.getTag();

    }


        holder.text.setText(standort.Name);

    return convertView;
}

class ListContent {
    TextView text;

}
}

我使用的功能

 loadLocationMenuList();
loadBussinessLunchLoc();



private void loadBussinessLunchLoc() {
  ServiceProxy.createWebServiceTask(getActivity(), new RemoteCallListener() {

   @Override
   public void onRemoteCallError(String response) {
    // TODO Auto-generated method stub

   }

   @Override
   public void onRemoteCallComplete(Object response) {
    Log.d("debug", "response is = " + response + "\t" + response.getClass());
    Standorts standorts = (Standorts) response;
    for(Standort standort : standorts)
      {
        if(standort.BusinessLunch==true){
           filteredstandorts.add(standort);
        }

      }

    locationMenuAdapter = new LocationMenuAdapter(StandorteFragment.this, filteredstandorts);
    menuItemListLoc2page.setAdapter(locationMenuAdapter);

   }

   @Override
   public void onNoInternetError() {
    // TODO Auto-generated method stub

   }

   @Override
   public void onNoAccess() {
    // TODO Auto-generated method stub

   }
  }, true).invokeGetStandorte();
 }

 private void loadLocationMenuList() {
  ServiceProxy.createWebServiceTask(getActivity(), new RemoteCallListener() {

   @Override
   public void onRemoteCallError(String response) {
    // TODO Auto-generated method stub

   }

   @Override
   public void onRemoteCallComplete(Object response) {
    Log.d("debug", "response is = " + response + "\t" + response.getClass());
    Standorts standorts = (Standorts) response;

    locationMenuAdapter = new LocationMenuAdapter(StandorteFragment.this, standorts);
    menuItemListLoc.setAdapter(locationMenuAdapter);

   }

   @Override
   public void onNoInternetError() {
    // TODO Auto-generated method stub

   }

   @Override
   public void onNoAccess() {
    // TODO Auto-generated method stub

   }
  }, true).invokeGetStandorte();
 }

我得到了下一个LogCat日志:

08-01 11:06:04.171: E/AndroidRuntime(16286): FATAL EXCEPTION: main
08-01 11:06:04.171: E/AndroidRuntime(16286): java.lang.NullPointerException
08-01 11:06:04.171: E/AndroidRuntime(16286):    at com.weinco.list.LocationMenuAdapter.getCount(LocationMenuAdapter.java:37)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.widget.ListView.setAdapter(ListView.java:454)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at com.weinco.fragments.StandorteFragment$10.onRemoteCallComplete(StandorteFragment.java:283)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at com.weinco.webservice.CallWebServiceTask.onPostExecute(CallWebServiceTask.java:543)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at com.weinco.webservice.CallWebServiceTask.onPostExecute(CallWebServiceTask.java:1)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.os.AsyncTask.finish(AsyncTask.java:417)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.os.Looper.loop(Looper.java:130)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at android.app.ActivityThread.main(ActivityThread.java:3744)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at java.lang.reflect.Method.invokeNative(Native Method)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at java.lang.reflect.Method.invoke(Method.java:507)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-01 11:06:04.171: E/AndroidRuntime(16286):    at dalvik.system.NativeStart.main(Native Method)

我没有想到要纠正这个问题,我在网上搜索了一些过滤器,但我发现它比java还要多,我真的能理解他们在做什么。

1 个答案:

答案 0 :(得分:0)

在他们告诉我使BusinessLunch成为布尔值的文档中,但是从webservice调用他们发送了一个值为0或1的整数。这就是为什么它在编译时没有显示任何内容。