1

arrayAdapter で拡張されたクラス内で警告ダイアログを表示したいと考えています。

このエラーが発生しています

android.view.WindowManager$BadTokenException: ウィンドウを追加できません -- トークン null はアプリケーション用ではありません

ここに私のコード、私が試したこと

public class DeteteAdapter extends ArrayAdapter<Gold> {
private int contexts = Intent.FLAG_ACTIVITY_NEW_TASK;
private Context context;
private List<Gold> subjects = new ArrayList<Gold>();
private TextView subject;
private TextView date_day;
private TextView time;
private ProgressDialog pDialog;
String name;
JSONParser jsonParser = new JSONParser();
// url to create new product
private static String url_create_product = "http://ayyappagold.com/ayyappa/test.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";

public static String month;
public static String year;

public DeteteAdapter(Context context, int textViewResourceId,
        List<Gold> objects) {
    super(context, textViewResourceId, objects);
    this.context = context;
    this.subjects = objects;
}

@Override
public int getCount() {
    return this.subjects.size();
}

@Override
public Gold getItem(int index) {
    return this.subjects.get(index);
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if (row == null) {
        // ROW INFLATION
        Log.d("ExamAdapter", "Starting XML Row Inflation ... ");

        LayoutInflater inflater = (LayoutInflater) this.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.custom_gold, parent, false);
        Log.d("ExamAdapter", "Successfully completed XML Row Inflation!");
    }

    // Get item
    Gold text = getItem(position);
    subject = (TextView) row.findViewById(R.id.textView1);

    time = (TextView) row.findViewById(R.id.textView2);

    String content = text.content;

    String times = text.time;

    subject.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            name = getItem(position).id.toString();
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

            // set title
            alertDialogBuilder.setTitle("Delete");

            // set dialog message
            alertDialogBuilder
                    .setMessage("This item will be deleted")
                    .setCancelable(false)
                    .setPositiveButton("Yes",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    // if this button is clicked, close
                                    // current activity
                                    new DeleteProduct().execute();
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    // if this button is clicked, just close
                                    // the dialog box and do nothing
                                    dialog.cancel();
                                }
                            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }
    });





    subject.setText(content.replace("*", "\n"));

    return row;
}

このクラスで警告ダイアログを表示するのを手伝ってください

4

3 に答える 3

1

これを試して

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( DeteteAdapter.this);
于 2013-04-09T11:24:51.787 に答える
0
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                context);

この行を次のように変更します。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                (Activity)context);

多分それはあなたを助けることができます

于 2013-06-11T07:47:28.697 に答える