私はそれが文脈であるべきだと知っています。しかし、正確にはコンテキストとは何ですか。通常、クラスでダイアログを作成するときは、次のようにします。
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;
}
}