在我的活动 Oncreate() 函数中,我正在调用AsyncTask。在那个PostExecute( ) 中,我创建了一些动态图库控件并调用ImageAdapterL.notifyDataSetChanged(); . 但我得到空指针异常。
我需要刷新活动而不调用 Oncreate() [B'coz in Oncreate only im call async Task]。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
new testAynscTask().execute();
}
private class testAynscTask extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... params) {
processTogetImages();
// TODO Auto-generated method stub
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
CreateDynamicGallery();
aImageAdapterL.notifyDataSetChanged();
}
}
public void CreateDynamicGallery(){
CategoryGalleryLayout = (LinearLayout) findViewById(R.id.linearLayout1);
Gallery g = new Gallery(getApplicationContext());
GalleryLayout.addView(g,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
g.setSpacing(15);
aImageAdapterL = new ImageAdapter(getApplicationContext());
g.setAdapter(aImageAdapterL);
g[positionP].setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View v, int position, long id) {
Toast.makeText(getBaseContext(), "" + position, Toast.LENGTH_SHORT).show();
}
});
}
}
提前致谢