开发者

image blank when orientation change?

I want to ask why my grid view can't show image after orientation change

I have set onConfigurationChange() and onRetainNonCofigurationInstance() but not resolve my problem.

this my code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.category_layout);

    data = getLastNonConfigurationInstance();

    setUpView();


}

privat开发者_JS百科e void setUpView() {
    gridview = (GridView) findViewById(R.id.gridlayout);
    if(data == null){
        imageGridViewAdapter = new ImageGridViewAdapter(this, category, image_category);
    }
    else{
        imageGridViewAdapter = (ImageGridViewAdapter) data;
    }
    gridview.setAdapter(imageGridViewAdapter);

    gridview.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1,
                final int arg2, long arg3) {

            if (subCategory[arg2].length > 1) {
                AlertDialog.Builder builder = new AlertDialog.Builder(
                        CategoryActivity.this);
                builder.setTitle(category[arg2]);
                builder.setItems(subCategory[arg2],
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int item) {
                                linkNewsCategory(arg2, item);
                            }
                        });
                builder.show();
            } else {
                linkNewsCategory(arg2, 0);
            }

        }

    });
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setUpView();
}



@Override
public ImageGridViewAdapter onRetainNonConfigurationInstance() {
    ImageGridViewAdapter a = new ImageGridViewAdapter(this, category, image_category);
    return a;
}

Is it bug on gridview?


finally i have find solution.. i have wrong adapter while set image and text..

this my old getView() :

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        v = mInflater.inflate(R.layout.category, null);
        holder = new ViewHolder();
        holder.category_title = (TextView) v.findViewById(R.id.text);
        holder.category_image = (ImageView) v.findViewById(R.id.image);
        v.setTag(holder);
    } else{
        holder = (ViewHolder) v.getTag();
    }

    holder.category_title.setText(data[position]);
    holder.category_image.setImageResource(image[position]);

    return v;
}

i change with this one:

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

    v = convertView;
    if(convertView == null){
        LayoutInflater li = activity.getLayoutInflater();
        v = li.inflate(R.layout.category, null);

        category_title = (TextView) v.findViewById(R.id.text);
        category_title.setText(data[position]);

        category_image = (ImageView) v.findViewById(R.id.image);
        category_image.setImageResource(image[position]);

    }
    return v;
}

for now it's can solve my problem..

thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜