0

ich einen Adapter mit array_restaruants haben, ist json, wenn ein Objekt, sondern Methode Ansicht Lauf 7 mal dont get 1 MalAndroid Get anzeigen Methode mehrmals eingeben

korrekt ist

wenn in Verfahren erhalten Kraft return 1 arbeiten nicht zählen i dont haben Idee für Problem ist mein Basisadapter oder warum?

Allzeit 7 Mal eingeben

public class AdapterName extends BaseAdapter { 
LayoutInflater inflater; 
Activity activity; 
private JSONArray array_restaruants; 
private AQuery aq; 


public AdapterName(Activity a,JSONArray cur_array_restaruants){ 
    activity= a; 
    array_restaruants=cur_array_restaruants; 

    aq=new AQuery(activity); 
    inflater =(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 



public static class ViewHolder{ 

    private Responsive_Linear_Layout linear_content; 
    private ImageView logo_empresa; 


} 

@Override 
public int getCount() { 
    return array_restaruants.length(); 
} 

@Override 
public Object getItem(int i) { 
    return i; 
} 

@Override 
public long getItemId(int i) { 
    return i; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    View vi=convertView; 
    ViewHolder holder; 

    if(convertView == null){ 

     vi = inflater.inflate(R.layout.template_parent_view, parent,false); 


     holder = new ViewHolder(); 
     holder.linear_content = (Responsive_Linear_Layout) vi.findViewById(R.id.linear_content); 
     holder.logo_empresa = (ImageView) vi.findViewById(R.id.logo_empresa); 



     vi.setTag(holder); 
    } 
    else { 
     holder = (ViewHolder) vi.getTag(); 

     try { 
      JSONObject obj_restaurant = array_restaruants.getJSONObject(position); 
      JSONArray coupons = obj_restaurant.getJSONArray("coupons"); 
      Log.e("obj_restaurant", obj_restaurant.toString()); 
      aq.id(holder.logo_empresa).image(obj_restaurant.getString("logo"), false, false); 

      for (int i = 0; i < coupons.length(); i++) { 
       LayoutInflater inflater2 = LayoutInflater.from(activity); 

       JSONObject obj_coupons = coupons.getJSONObject(i); 
       View vi2 = inflater2.inflate(R.layout.template_for_items, null, false); 
       vi2.setId(i); 
       final TextView text_coupon = (TextView) vi2.findViewById(R.id.text_coupon); 
       text_coupon.setText(obj_coupons.getString("name")); 
       text_coupon.setId(obj_coupons.getInt("id")); 

       text_coupon.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         try { 
          Toast.makeText(activity, String.valueOf(v.getId()), Toast.LENGTH_LONG).show(); 


         } catch (Exception e) { 
          e.printStackTrace(); 
         } 

        } 
       });  imageButton.setBackground(activity.getResources().getDrawable(R.drawable.login_usuario_1)); 
       holder.linear_content.addView(vi2); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    return vi; 
} 

}

+1

Mögliche Duplikate von [benutzerdefinierte ListView-Adapter getView-Methode wird mehrmals aufgerufen, und in keiner kohärenten Reihenfolge] (http://stackoverflow.com/questions/2618272/custom-listview-adapter-getview-method-being-called- Mehrfach-und-in-kein-co) –

Antwort

-2

Ihrer ListView-wrap_content Wahrscheinlich stellen Sie Höhe, dann sollten Sie das nicht tun. Stellen Sie sicher, dass Ihre Größe match_parent ist. Watch google io video über ListView: https://www.youtube.com/watch?v=wDBM6wVEO70 Es hat ein paar Tipps.

+0

nicht funktionieren Mann ist falsch – pedroooo