如何让微调器显示Android中的完整项目

时间:2014-06-16 07:40:39

标签: android user-interface android-spinner

我有Android Spinner的问题。我使用BaseAdapter定制了一个适配器。但是当它第一次显示时,它不会显示所有项目(我只有6项)。以下是截图 http://pik.vn/2014999186b9-448d-44ed-bd9b-c37484b368c6.png

当我第二次点击Spinner时,它正常显示。以下是截图。如何在第一时间显示这样的完整项目? http://pik.vn/201454ed3e5b-4c67-4e9c-b8c6-feaf90c5dfb4.png

更新代码:

以下是适配器:

public class CategoryAdapter extends BaseAdapter实现SpinnerAdapter {

Context mContext;
List<CategoryModel> data;
int selectedCate;
boolean isSpinner;
Spinner spn;

public CategoryAdapter(Context context, List<CategoryModel> data, boolean isSpinner, Spinner spn) {
    mContext = context;
    selectedCate = 0;
    this.data = data;
    this.isSpinner=isSpinner;
    this.spn = spn;
}


@Override
public int getCount() {
    return data.size();
}

@Override
public Object getItem(int position) {
    if (position < data.size()) {
        return data.get(position);
    } else {
        return null;
    }
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.inflater_category_spinner, parent, false);

        }
        TextView tvName = (TextView) convertView.findViewById(R.id.inflater_category_spinner_tv);
        tvName.setSelected(spn.isSelected());
        tvName.setText(data.get(position).getName());
        return convertView;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = LayoutInflater.from(mContext);
    convertView = inflater.inflate(R.layout.inflater_category, parent, false);
    ImageView img = (ImageView) convertView.findViewById(R.id.inflater_cate_image);
    if (!data.get(position).getName().equals(parent.getContext().getString(R.string.browse))) {
        Log.d("postion", "" + position);
        UrlImageViewHelper.setUrlDrawable(img, data.get(position).getImage().getUrl());
    } else {
        img.setImageResource(R.drawable.ic_everything);
    }

    TextView tvName = (TextView) convertView.findViewById(R.id.inflater_cate_tv_name);
    tvName.setText(data.get(position).getName());
    return convertView;

}

public void swapView(int position) {
    selectedCate = position;
}

}

以下是Activity中的代码init Spinner

             categoryAdapter = new CategoryAdapter(HomeActivity.this, result,true, mSpnActionbarCenterTitle);
            mSpnActionbarCenterTitle.setAdapter(categoryAdapter);

1 个答案:

答案 0 :(得分:0)

问题来自ImageView的高度,它是通过延迟加载器包装内容和加载,并且加载图像时微调器的高度不会改变。我的解决方案是修复ImageView的大小。