簡體   English   中英

Android Adapter AlertDialog錯誤

[英]Android Adapter AlertDialog error

我在另一個類的列表視圖中使用的Adapter類中有以下代碼。

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Introduceti parola:");
final EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
builder.setView(input);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which)
    {
         hash.put("name", Rooms.name);
         hash.put("parola", input.getText().toString());
         site = siteul + "/join";
         new ATask((ViewHolder) v.getTag()).execute(site);
    }
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.cancel();
    }
});
builder.show();

問題是,當我觸發動作時,我在builder.show()行中收到此錯誤

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

我以為getContext()有問題,但是在同一Adapter類的此代碼中不會產生任何錯誤:

Toast.makeText(getContext(), "Cool message!", Toast.LENGTH_LONG).show();

那可能是什么問題呢?

getContext()替換為ActivityName.this

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM