listView项目在Android 2.3的滚动上消失

时间:2014-02-06 08:01:02

标签: android android-layout listview android-listview

片段加载时

enter image description here。 滚动后数据enter image description here出现平滑数据。但又消失了

滚动内容上的Android列表视图仅对2.3不可见。 工作正常4.0及以上。 问题是,当我滚动ListView时,数据消失,图像将只显示。 如果我顺利滚动并点击一到两秒钟。在列表上将显示数据,但滚动时数据将消失。

以下是我的适配器代码 -

public class RestaurantListAdapter extends BaseAdapter {
    private ArrayList<RestaurantList> restaurantList;
    private LayoutInflater inflater;
    private ImageLoader imageLoader;
    private Context context;
    private ViewHolder viewHolder = null;
    DisplayImageOptions options;

    public RestaurantListAdapter(Activity activity,
            ArrayList<RestaurantList> restaurantList) {
        this.context = activity;
        this.restaurantList = restaurantList;

        this.inflater = LayoutInflater.from(this.context);

        imageLoader = ImageLoader.getInstance();
        options = new DisplayImageOptions.Builder().cacheInMemory(true)
                .cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565).build();
    }

    public int getCount() {
        return restaurantList.size();
    }

    public Object getItem(int position) {
        return position;
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            viewHolder = new ViewHolder();

            convertView = inflater.inflate(
                    R.layout.restaurant_list_item_layout, null);

            viewHolder.restaurantNameTextView = (TextView) convertView
                    .findViewById(R.id.restaurantNameTextView);
            viewHolder.restaurantAddressTextView = (TextView) convertView
                    .findViewById(R.id.restaurantAddressTextView);
            viewHolder.restaurantPinTextView = (TextView) convertView
                    .findViewById(R.id.restaurantPinTextView);
            viewHolder.restaurantPhoneTextView = (TextView) convertView
                    .findViewById(R.id.restaurantPhoneTextView);
            viewHolder.favoriteImageButton = (ImageButton) convertView
                    .findViewById(R.id.favoriteImageButton);


            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        RestaurantList restaurant = restaurantList.get(position);

        viewHolder.restaurantNameTextView.setText(restaurant
                .getRestaurantName());
        viewHolder.restaurantAddressTextView.setText(restaurant
                .getRestaurantAddress());
        viewHolder.restaurantPinTextView.setText(restaurant.getRestaurantPin());
        viewHolder.restaurantPhoneTextView.setText(restaurant
                .getRestaurantPhone());
        viewHolder.favoriteImageButton.setFocusable(false);

        viewHolder.restaurantNameTextView.setVisibility(View.VISIBLE);


        return convertView;
    }

    static class ViewHolder {
        TextView restaurantNameTextView;
        TextView restaurantAddressTextView;
        TextView restaurantPinTextView;
        TextView restaurantPhoneTextView;
        ImageButton favoriteImageButton;
        ImageView restaurentImageView;
    }

}

2 个答案:

答案 0 :(得分:1)

只需添加

android:cacheColorHint="@android:color/transparent"到xml布局中的ListView

答案 1 :(得分:0)

我怀疑这行

  viewHolder.restaurantNameTextView.setVisibility(View.VISIBLE);

显然,Android 2.3中存在一些关于设置视图可见性的问题 (来源:http://www.kittehface.com/2011/03/view-visibility-bug-on-android-233.html

尝试将其取下并查看发生了什么... BTW为什么要将视图设置为可见? 似乎没有任何区别......