Я пытался открыть пользовательское диалоговое окно при нажатии на маркер карты Google. Я использую этот код для переопределения метода onTap () для itemizedOverlay calss.
protected boolean onTap(int index) {
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView textName = (TextView) layout.findViewById(R.id.text);
textName.setText("Here is the Name");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
return super.onTap(index);
}
Вот пользовательский макет диалога xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
Но я получаю это исключение при нажатии на маркер
02-07 16:46:51.768: E/AndroidRuntime(315): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
это точный пример, приведенный на http://developer.android.com/guide/topics/ui/dialogs.html
любая помощь, пожалуйста ...
Спасибо.