Search code examples
androidandroid-layoutinfowindowsettext

App crashing on setText in InfoWindow


I have this problem with my InfoWindow in my Android app. When I run this code:

@Override
public View getInfoWindow(Marker marker) {

    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.lkonty, null);

    TextView txtName= (TextView) findViewById(R.id.txtName);
    txtName.setText(marker.getTitle());
    return view;

The app crashes while running the setText method. I found a solution by adding this line of code:

setContentView(R.layout.lkonty);

The app is no longer crashing but now the InfoWindow fills the whole screen and I don't know how to change that.


Solution

  • Try this

     View v = LayoutInflater.from(parent.getContext())
     .inflate(R.layout.lkonty,parent,false);
    
    
    TextView txtName= (TextView) view.findViewById(R.id.txtName);
    
    txtName.setText(marker.getTitle());