0

我有array_restaruants一个适配器是JSON时1对象,但方法得到视图运行7次不要1次是正确的Android开查看输入方法多次

如果方法得到算力回报1不工作我没有问题的想法是我的基础适配器或为什么?

所有的时间进入7倍

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

可能重复[自定义列表视图适配器getView方法多次调用,并没有连贯的顺序](http://stackoverflow.com/questions/2618272/custom-listview-adapter-getview-method-being-called-多次和在 - 没有co) –

回答

-2

也许您设置ListViewwrap_content的高度,你不应该这样做。确保你的身高是match_parent。观看关于ListView的谷歌io视频:https://www.youtube.com/watch?v=wDBM6wVEO70它有一些提示。

+0

不工作的人是错的 – pedroooo