我有一个带有array_restaruants的适配器是json,当1个对象但是方法获取视图运行7次时没有1次是正确的
如果在方法中获取计数强制返回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;
}
}
答案 0 :(得分:-2)
您可能将ListView
的高度设置为wrap_content
,您不应该这样做。确保你的身高是match_parent
。观看关于ListView
的谷歌io视频:https://www.youtube.com/watch?v=wDBM6wVEO70它有一些提示。