8

यह मेरा GoogleMap के लिए नया मार्कर जोड़ने के लिए मेरी कोड है:खाली InfoWindow जब मार्कर क्लिक किया जाता है

MarkerOptions m = new MarkerOptions(); 
m.title(title); 
m.snippet(snippet); 
m.position(location); 
mMap.addMarker(m); 

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { 
     @Override 
     public void onInfoWindowClick(Marker marker) { 
      Toast.makeText(DemoActivity.this, "WindowClicked: "+ marker.getTitle() + ":" + marker.getSnippet(), 
        Toast.LENGTH_SHORT).show(); 
     } 
    }); 

अब यह सिर्फ ठीक काम करता है जब मेरे title और snippet अंग्रेजी में हैं। infoWindow और Toast अपेक्षा के अनुसार काम करता है।

हालांकि, मेरे मामले में के रूप में, title और snippet अरबी में हैं, Toast ठीक काम करता है लेकिन InfoWindow खाली खिड़की को दर्शाता है।

ऐसा लगता है कि मुझे अरबी भाषा से संबंधित एक बग की तरह लगता है। क्या इसके आसपास काम करने का कोई तरीका है?

उत्तर

6

इस बारे में एक तरीका एक कस्टम जानकारी विंडो दिखाने के लिए होगा। आप इसे InfoWindowAdapter बनाकर और GoogleMap.setInfoWindowAdapter() के साथ सेट करके कर सकते हैं।

डिफ़ॉल्ट जानकारी विंडो को प्रतिस्थापित करने के लिए, getInfoWindow (मार्कर) को अपने कस्टम प्रतिपादन के साथ ओवरराइड करें और getInfoContents (मार्कर) के लिए शून्य वापस करें। डिफ़ॉल्ट जानकारी विंडो फ्रेम (कॉलआउट बबल) के अंदर केवल जानकारी विंडो सामग्री को प्रतिस्थापित करने के लिए, getInfoWindow (मार्कर) में शून्य वापस करें और इसके बजाय getInfoContents (मार्कर) ओवरराइड करें।

अधिक जानकारी: https://developers.google.com/maps/documentation/android/marker#info_windows

+0

पूरी तरह से काम करता है। धन्यवाद! – iTurki

+0

@iturki यह मेरी समस्या का समाधान नहीं किया। अरबी का उपयोग करते समय भी मेरे पास खाली खिड़की है। इस मुद्दे को हल करने के लिए आपने वास्तव में क्या किया?> – AlAsiri

+0

@AlAsiri मेरा उत्तर देखें। – iTurki

7

@jimmithy जवाब मेरे सवाल को हल किया।

यह सिर्फ तीन चरणों की कार्यान्वयन this project से इसके बारे में है:

चरण 1: अपने infoWindow के लेआउट बनाएँ।

<?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="wrap_content" 
android:orientation="horizontal"> 

<ImageView 
android:id="@+id/icon" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:padding="2dip" 
android:src="@drawable/ic_launcher" 
android:contentDescription="@string/icon"/> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<TextView 
android:id="@+id/title" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="25sp" 
android:textStyle="bold"/> 

<TextView 
android:id="@+id/snippet" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="15sp"/> 
</LinearLayout> 

</LinearLayout> 

चरण 2:: InfoWindowAdapter अपने क्रियान्वयन बनाएं यहाँ popup.xml कोड है।

class PopupAdapter implements InfoWindowAdapter { 
    LayoutInflater inflater=null; 

    PopupAdapter(LayoutInflater inflater) { 
    this.inflater=inflater; 
    } 

    @Override 
    public View getInfoWindow(Marker marker) { 
    return(null); 
    } 

    @Override 
    public View getInfoContents(Marker marker) { 
    View popup=inflater.inflate(R.layout.popup, null); 

    TextView tv=(TextView)popup.findViewById(R.id.title); 

    tv.setText(marker.getTitle()); 
    tv=(TextView)popup.findViewById(R.id.snippet); 
    tv.setText(marker.getSnippet()); 

    return(popup); 
    } 
} 

चरण 3:: यहाँ PopupAdapter वर्ग है अपनी गतिविधि में, GoogleMap अपने एडॉप्टर को सेट करें:

mMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater())); 

और आप सेट कर रहे हैं!

+0

कक्षा को बढ़ाने में त्रुटि, @ इस लाइन पॉपअप = inflater.inflate देखें (आर .layout.popup, शून्य); आगे, 02-06 14: 40: 54.950: ई/एंड्रॉइड रनटाइम (24275): द्वारा: android.content.res।संसाधन $ NotFoundException: संसाधन एक ड्रायबल (रंग या पथ) नहीं है: TypedValue {t = 0x1/d = 0x7f020078 a = -1 r = 0x7f020078} –

+0

धन्यवाद, निश्चित, उपयोगी प्रश्न और उत्तर .. –

3

आपको इस आदेश का उपयोग करना चाहिए .title("\u200e"+"عربی").

+0

बिल्कुल सही! छोटा एवं सुन्दर!!! – offset

संबंधित मुद्दे