2

レイアウトXMLファイルからリソースを取得しようとしsetText()ています。TextView

ユーザーがGoogleマップのマーカーをクリックしたとき。これは私がonTap()マーカーのために書いたコードです。

追加しないまでTextView、私のコードは正常に機能します。マーカーをクリックするとダイアログが表示され、すべてが機能します。

これらの行をに追加するonTap()と、アプリケーションを実行してマーカーをクリックすると、と表示されなくなりますUnfortunately map has stopped

LogCatエラーメッセージが表示されます:

入力イベントのディスパッチ中にエラーが発生しました

OverlayItemクラスを拡張するクラスCustomOverlayItemを作成しました。Tv_descriptionTextViewは、レイアウトファイルcutom_dialog.xmlの一部です。

ユーザーがマーカーをクリックしたときに、実行時に動的に呼び出すsetText()にはどうすればよいですか?TextView

@Override
protected boolean onTap(int index) {
    Dialog dialog = new Dialog(context, android.R.style.Theme_Dialog);
    TextView tv_description = new TextView(context);
    tv_description = (TextView) dialog.findViewById(R.id.tv2_description);
    tv_description.setText("checking");

    dialog.setContentView(R.layout.custom_dialog);
    dialog.show();

    return true;

}

logcatの出力は次のとおりです。

07-31 11:59:16.271: E/Trace(2143): error opening trace file: No such file or directory (2)
07-31 11:59:17.741: E/ZoomButtonsController(2143): Cannot make the zoom controller visible if the owner view is not attached to a window.
07-31 11:59:18.151: E/MapActivity(2143): Couldn't get connection factory client
07-31 11:59:28.531: E/InputEventReceiver(2143): Exception dispatching input event.
07-31 11:59:28.541: E/MessageQueue-JNI(2143): Exception in MessageQueue callback: handleReceiveCallback
07-31 11:59:28.591: E/MessageQueue-JNI(2143): java.lang.NullPointerException
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.incubers.map.Markers.onTap(Markers.java:41)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.View.dispatchTouchEvent(View.java:7127)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.View.dispatchPointerEvent(View.java:7307)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.os.MessageQueue.nativePollOnce(Native Method)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.os.MessageQueue.next(MessageQueue.java:125)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.os.Looper.loop(Looper.java:124)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at android.app.ActivityThread.main(ActivityThread.java:4745)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at java.lang.reflect.Method.invokeNative(Native Method)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at java.lang.reflect.Method.invoke(Method.java:511)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-31 11:59:28.591: E/MessageQueue-JNI(2143):   at dalvik.system.NativeStart.main(Native Method)
07-31 11:59:28.681: E/AndroidRuntime(2143): FATAL EXCEPTION: main
07-31 11:59:28.681: E/AndroidRuntime(2143): java.lang.NullPointerException
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.incubers.map.Markers.onTap(Markers.java:41)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.View.dispatchTouchEvent(View.java:7127)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.View.dispatchPointerEvent(View.java:7307)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.os.MessageQueue.nativePollOnce(Native Method)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.os.MessageQueue.next(MessageQueue.java:125)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.os.Looper.loop(Looper.java:124)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at java.lang.reflect.Method.invokeNative(Native Method)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at java.lang.reflect.Method.invoke(Method.java:511)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-31 11:59:28.681: E/AndroidRuntime(2143):     at dalvik.system.NativeStart.main(Native Method)
4

2 に答える 2

1

あなたはこのようにあなたを更新しようとすることができTextViewますHandler

public Handler MainHandler = new Handler() 
{
    @Override
    public void handleMessage(Message msg) 
    {
        _mytextview.setText((String)msg.obj);
    }
}; 

であなたからのメッセージを送信しますonTap()

Message _message = new Message();
_message.obj = "my text to update";
MainHandler.sendMessage(_message);

お役に立てば幸いです:-)

[編集]ここで私が試したコード:

custom_dialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:id="@+id/Overlay_Layout" android:orientation="vertical">
<TextView android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="wrap_content" android:layout_height="wrap_content"  android:layout_margin="5dp" android:text="@string/empty" android:id="@+id/tv2_description">    </TextView>
</LinearLayout>

私の中でonTouchEvent()

Dialog dialog = new Dialog(_context, android.R.style.Theme_Dialog);
dialog.setContentView(R.layout.custom_dialog);
TextView tv_description = (TextView) dialog.findViewById(R.id.tv2_description);
tv_description.setText("checking");
dialog.show();

それは私のために働いています。

于 2012-07-31T06:43:58.770 に答える
1

この線は間違っていると思います。

tv_description = (TextView) dialog.findViewById(R.id.tv2_description);

TextViewダイアログに存在しないを見つけようとしています。

ダイアログはデフォルトDialogであり、これはありませんTextView。上記の行の前に、setContentView()これを含むレイアウトを使用してダイアログでを実行します。TextView

于 2012-07-31T07:02:08.247 に答える