suja
suja

Reputation: 1288

While using custom InfoWindow getting NullPointerException

I am using a custom InfoWindow in my app. I have two question related to it.

  1. Is it possible to make multiline snippet in InfoWindow

Say am adding some data lets say I need to show LATTITUDE and LONGITUDE when I click on marker. Normally if u set these values in snippet they appear on same line. I would like to show them on two line. Is that possible

I googled about multiline snippet and couldn't find anything much useful so came up with the idea of customising InfoWindow.

2.Below show is my custom InfoWindow which gives me NullPointerException

Getting exception from try-catch loop. I followed some code I found while googleing but it's not working.

 private class MyCustomInfoWindow implements InfoWindowAdapter{


    private View view;

    public MyCustomInfoWindow(){

    }

    @Override
    public View getInfoContents(Marker markr) {
        // TODO Auto-generated method stub


        return null;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        // TODO Auto-generated method stub

        view = getLayoutInflater().inflate(R.layout.mycustom_infowindow, null);
        TextView marker_heading = (TextView)findViewById(R.id.marker_heading);
        try{

            String m_heading = marker.getId();
            marker_heading.setText(m_heading);

        }
        catch(Exception exx){
            Toast.makeText(getApplicationContext(), "getInfoWindow Error is  " + marker_heading.length(), Toast.LENGTH_LONG).show();

        }
        return view;
    }



}    

My custom

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">    

  <TextView 
    android:id="@+id/marker_heading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:typeface="serif"
    android:textStyle="bold" 
    />    

</LinearLayout>

Using Google Maps V2

Could someone please tell me where am going wrong .

Upvotes: 0

Views: 539

Answers (3)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

Use

TextView marker_heading = (TextView)view.findViewById(R.id.marker_heading);

to initialize marker_heading TextView instance because TextView is inside mycustom_infowindow layout

Upvotes: 2

Piyush
Piyush

Reputation: 18923

Use

TextView marker_heading = (TextView)view.findViewById(R.id.marker_heading); 

you have to pass your View's object as a refernce to find id for TextView

Upvotes: 1

M D
M D

Reputation: 47817

You should replace this

  TextView marker_heading = (TextView)findViewById(R.id.marker_heading);

With

  TextView marker_heading = (TextView)view.findViewById(R.id.marker_heading);

Upvotes: 1

Related Questions