Filter an arraylist to use in an image adapter

Entonces tengo un ImageAdapter that I need to use in 2 ListView of 2 different layouts.I use it for the first, and then want to filter the array, put those values in another array that i use for the second listview.

My Image Adapter

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;

}
}

The functions that i use

 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();
 }

I get the next LogCat Log:

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)

I have no ideea what i have to do to correct this, i searched the net for some filters, but what i found was more java than android, and i could really understand what they were doing.

preguntado el 31 de julio de 12 a las 12:07

You should add your logcat output so we can get the origin of the force close. -

no more Force Close, so LogCat won't help. I get the second list with the same number of lines, but instead of having streets, all the lines just say "False" -

How exactly do you filter the values, looking at your code you're using basically the same code? -

ok, i got it, i have to filter the arraylist "standorts" and then only run the second image adapter. Just have to learn to do that now :p -

standorts in the adapter(a.k.a filteredstandorts by the code in onRemoteCallComplete) es null y cuando el getCount El método se llama NullPointerException is thrown(my guess is that you don't initialize filteredstandorts y como standort.BusinessLunch is false you only see the exception in the adapter). Nobody can help you if you don't put some details regarding what type of data you have(like the Standorts, Standort class), how do you plan to sort it etc. -

1 Respuestas

in the documentation they told me to make BusinessLunch a boolean, but from the webservice call they were sending me an integer with the value of 0 or 1. That's why it didn't show anything when it was compiled.

Respondido 01 ago 12, 10:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.