我知道它应该是上下文。 但是,上下文究竟是什么。 通常当我在一类 创建一个对话框我做这样的事情:对话构造函数里面的东西
final Dialog dialog = new Dialog(this);
但现在我想在的AsyncTask来创建一个对话框<> 因此我不能这样做上述原因的AsyncTask不显然是一种语境。 AsyncTask本身就是一个类,也就是说现在它不是子类。
public class popTask extends AsyncTask<Void, Void, String> {
Context con =
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
final Dialog dialog = new Dialog(con);
dialog.setContentView(R.layout.custom);
dialog.setTitle("New & Hot advertise");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.yoda);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
@Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
return null;
}
}
。 –
我可以通过执行pTask.execute()来执行; –
是的,我已经包含了一个OR,它表示两种解决方案中的任何一种,但不是同时存在。如果你使用第一个选项,那么你可以使用'pTask.execute()'。希望答案是有帮助的。 –