我認爲問題出在你的Adapter類上。 嘗試使用此代碼:
內活動onCreate方法:
GridView grid = (GridView) findViewById(R.id.gridView);
grid.setAdapter(new Adapter(this));
Adapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Adapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflator;
public Adapter(Context context) {
this.mContext = context;
mInflator = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return 10;
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
static class ViewHolder {
private TextView appLable;
private ImageView appICon;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
final ViewHolder vHolder = new ViewHolder();
view = mInflator.inflate(R.layout.item, null);
vHolder.appLable = (TextView) view.findViewById(R.id.lable);
vHolder.appICon = (ImageView) view.findViewById(R.id.icon);
view.setTag(vHolder);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.appLable.setText("position " + position);
return view;
}
}
將這個清單裏面活動標籤:
android:configChanges="orientation"
希望它會幫助你:)
使用片段可能會給你想要的東西,因爲它可以更好地控制配置更改。 –
該鏈接是http://developer.android.com/guide/topics/resources/runtime-changes.html –