1

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

我的图像适配器

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 而不是 android,我真的能理解他们在做什么。

4

1 回答 1

0

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

于 2012-08-01T09:11:07.490 回答