方向改变时图像空白?
我想问为什么我的网格视图在方向更改后无法显示图像
我设置了 onConfigurationChange() 和 onRetainNonCofigurationInstance() 但没有解决我的问题。
这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.category_layout);
data = getLastNonConfigurationInstance();
setUpView();
}
private 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;
}
这是 gridview 上的错误吗?
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();
}
private 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于我找到了解决方案..
我在设置图像和文本时有错误的适配器..
这是我的旧 getView() :
我用这个进行更改:
现在它可以解决我的问题..
谢谢
finally i have find solution..
i have wrong adapter while set image and text..
this my old getView() :
i change with this one:
for now it's can solve my problem..
thanks