ListView的项目上消失滚动为Android

ListView的项目上消失滚动为Android

本文介绍了ListView的项目上消失滚动为Android 2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

有关片段的负荷。
顺利滚动数据后出现。但同样disappera

Android的列表视图上滚动的内容仅适用于2.3得到无形。
做工精细的4.0及以上。
问题是,当我滚动数据获取消失,图像将显示仅在ListView。
如果我平滑滚动和点击一至两秒。在列表中的数据显示将会而是滚动数据获取消失。

下面是我的适配器code -

 公共类RestaurantListAdapter延伸BaseAdapter {
    私人的ArrayList< RestaurantList> restaurantList;
    私人LayoutInflater吹气;
    私人ImageLoader的ImageLoader的;
    私人上下文的背景下;
    私人ViewHolder viewHolder = NULL;
    DisplayImageOptions选择;    公共RestaurantListAdapter(活动活动,
            ArrayList的< RestaurantList> restaurantList){
        this.context =活动;
        this.restaurantList = restaurantList;        this.inflater = LayoutInflater.from(this.context);        ImageLoader的= ImageLoader.getInstance();
        选项​​=新DisplayImageOptions.Builder()。cacheInMemory(真)
                .cacheOnDisc(真).bitmapConfig(Bitmap.Config.RGB_565).build();
    }    公众诠释的getCount(){
        返回restaurantList.size();
    }    公共对象的getItem(INT位置){
        返回的位置;
    }    众长getItemId(INT位置){
        返回的位置;
    }    公共查看getView(INT位置,查看convertView,父母的ViewGroup){        如果(convertView == NULL){
            viewHolder =新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);
        }其他{
            viewHolder =(ViewHolder)convertView.getTag();
        }        RestaurantList餐厅= restaurantList.get(位置);        viewHolder.restaurantNameTextView.setText(餐厅
                .getRestaurantName());
        viewHolder.restaurantAddressTextView.setText(餐厅
                .getRestaurantAddress());
        viewHolder.restaurantPinTextView.setText(restaurant.getRestaurantPin());
        viewHolder.restaurantPhoneTextView.setText(餐厅
                .getRestaurantPhone());
        viewHolder.favoriteImageButton.setFocusable(假);        viewHolder.restaurantNameTextView.setVisibility(View.VISIBLE);
        返回convertView;
    }    静态类ViewHolder {
        TextView的restaurantNameTextView;
        TextView的restaurantAddressTextView;
        TextView的restaurantPinTextView;
        TextView的restaurantPhoneTextView;
        的ImageButton favoriteImageButton;
        ImageView的restaurentImageView;
    }}


解决方案

只需添加

的android:cacheColorHint =@机器人:彩色/透明来在你的XML布局你的ListView

on load of Fragment. after scrolling smoothly data appears. but again disappera

Android List View on scroll content gets invisible only for 2.3.working fine for 4.0 and above.problem is when I scroll the ListView the data gets disappear and images will be shown only.If i scroll smoothly and Tap for one or two sec. on list the data will shown but on scroll the data gets disappear.

Below is my adapter code -

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;
    }

}
解决方案

simply add

android:cacheColorHint="@android:color/transparent" to your ListView in your xml layout

这篇关于ListView的项目上消失滚动为Android 2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:26