私のアラートダイアログをarrayAdapterで動作させようとしています。これは私の機能がどのように見えるかです。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Noodnummers currentNoodnummer = noodnummers.get(position);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(layoutResourceId, parent, false);
TextView txt_noodnummer_name = (TextView) rowView.findViewById(R.id.txt_noodnummer_name);
txt_noodnummer_name.setText(currentNoodnummer.naam);
TextView txt_noodnummer_telefoon = (TextView) rowView.findViewById(R.id.txt_noodnummer_telefoon);
txt_noodnummer_telefoon.setText(Html.fromHtml(currentNoodnummer.telefoonNummer));
txt_noodnummer_telefoon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
//To change body of implemented methods use File | Settings | File Templates.
try {
new AlertDialog.Builder(this)
.setTitle("")
.setMessage("Bent u zeker dat u" + currentNoodnummer.telefoonNummer + "wilt bellen?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
String uri = currentNoodnummer.telefoonNummer;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
v.getContext().startActivity(intent);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();
} catch (ActivityNotFoundException activityException) {
Log.e("genkonstage", "Call failed", activityException);
}
}
});
return rowView;
}
最初の問題は、 new AlertDialog.Builder(this)
単語のエラーが表示されることですthis
。次に、おそらくコンテキストを使用する必要があることがわかりました。しかし、私が言うnew AlertDialog.Builder(context)
とエラーは発生しませんが、アプリをクリックするとクラッシュします。
誰かがこれで私を助けることができますか?
編集
06-18 10:56:20.689 12980-12980/be.appmax.genkOnStage E/AndroidRuntime: FATAL EXCEPTION: main
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
at be.appmax.genkOnStage.adapters.NoodnummersArrayAdapter$1.onClick(NoodnummersArrayAdapter.java:57)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
内部での arrayAdapter の作成NoodnummersActivity
ListView listView = (ListView) findViewById(R.id.listViewNoodnummers);
//addList(noodnummersArrayList, listView);
NoodnummersArrayAdapter adapter = new NoodnummersArrayAdapter(getBaseContext(), R.layout.noodnummers_list, noodnummersArrayList);
// fill the listview with adapter.
listView.setAdapter(adapter);
setListViewHeightBasedOnChildren(listView);