我有一个列表活动。当我单击此列表活动的一个项目时,调用的活动需要时间来加载,因此我想添加一个加载对话框,该对话框应在活动开始后立即消失。但我做不到。我也很困惑在列表活动或被调用活动中添加对话框。在将对话框添加到后面的活动时,我收到此错误:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@40521cd0 is not valid; is your activity running?
这就是我插入对话框的方式
super.onCreate(savedInstanceState);
setContentView(R.layout.graphview);
ProgressDialog pdialog=new ProgressDialog(this);
pdialog.setCancelable(true);
pdialog.setMessage("Loading ....");
pdialog.show();
请告诉我出了什么问题。
这是我的完整代码:
public class List12 extends ListActivity {
private List<String> item = null;
private List<String> path = null;
private String root;
private TextView myPath;
private ProgressDialog mProgressDialog;
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle b=this.getIntent().getExtras();
final String path=(String) b.get("key");
setContentView(R.layout.list13);
myPath = (TextView)findViewById(R.id.path);
root = Environment.getExternalStorageDirectory().getPath()+"/"+path+"/raw/";
File f = new File(root);
File[] files = f.listFiles();
if(files==null)
{
Toast.makeText(this, "No stored records for the patient", Toast.LENGTH_LONG).show();
List12.this.finish();
}
// TODO Auto-generated catch block
else
getDir(root, path);
}
private void getDir(String dirPath, String id)
{
myPath.setText("Stored data for "+id);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
if(!file.isHidden() && file.canRead()){
path.add(file.getPath());
if(file.isDirectory()){
item.add(file.getName() + "/");
}else{
item.add(file.getName());
}
}
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
File file = new File(path.get(position));
Bundle b=new Bundle();
String array = file.getAbsolutePath();
b.putString("key",array);
b.putBoolean("flag", false);
Intent in = new Intent(getParent(), Display.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
in.putExtras(b);
parentActivity.startChildActivity("Dsiplay", in);
ProgressDialog pdialog=new ProgressDialog(List12.this);
pdialog.setCancelable(true);
pdialog.setMessage("Loading ....");
pdialog.show();
}}