我在ListActivity中有一个GridView,我需要GridView在完成释放资源时自行销毁。单击某个项目时,永远不会调用onPause和onDestroy。我如何让他们开火?这是我的代码:
public class ViewOutfitsActivity extends ListActivity {
public static final String TAG = ChooseStickersActivity.class.getSimpleName();
private int mMenuId;
dbhelper db;
List<Outfit> mListContents;
Context ctx;
private void setMmenuId() {
mMenuId = 0;
// You can be pretty confident that the intent will not be null here.
Intent intent = getIntent();
// Get the extras (if there are any)
Bundle extras = intent.getExtras();
if (extras != null) {
if (extras.containsKey("menuId")) {
mMenuId = extras.getInt("menuId");
}
}
}
private void finishMyActivity(){
this.finish();
}
@Override
protected void onPause() {
GridView gridView = (GridView) findViewById(R.id.gridviewViewOutfits);
int count = gridView.getCount();
for (int i = 0; i < count; i++) {
ImageView v = (ImageView) gridView.getChildAt(i);
if (v != null) {
if (v.getDrawable() != null) v.getDrawable().setCallback(null);
}
}
super.onPause();
}
@Override
protected void onDestroy() {
GridView gridView = (GridView) findViewById(R.id.gridviewViewOutfits);
int count = gridView.getCount();
for (int i = 0; i < count; i++) {
ImageView v = (ImageView) gridView.getChildAt(i);
if (v != null) {
if (v.getDrawable() != null) v.getDrawable().setCallback(null);
}
}
super.onDestroy();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_outfits);
ctx = this.getApplicationContext();
setMmenuId();
GridView gridview = (GridView) findViewById(R.id.gridviewViewOutfits);
ViewOutfitsImageAdapter ia = new ViewOutfitsImageAdapter(this.getApplicationContext(), mMenuId);
gridview.setAdapter(ia);
mListContents = ia.getMlistContents();
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
try {
String imagePath = getOutfitInternalPath(position);
String externalImagePath = getOutfitExternalPath(position);
passClothingItemToViewSingleOutfitActivity(imagePath, externalImagePath);
finishMyActivity();
finish();
} catch (Exception e) {
Log.v(e.getMessage(), e.getMessage());
}
}