1

OnClick doesn't work. Nothing happens after clicking on layout. It seems like it is clickable, because layout changes its color, but new layout doesn't open.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/window"
     android:layout_width="295dp"
     android:layout_height="wrap_content"
     android:orientation="vertical" 
     android:background="@drawable/editborder"
     android:clickable="true"
     android:onClick="openBigImage">

Here is more code for Main Activity:

 public class MyMapActivity extends FragmentActivity implements LocationListener
 {

     private Marker marker;
     private Hashtable<String, String> markers;
     private ImageLoader imageLoader;
     private DisplayImageOptions options;
     private GoogleMap map;
     private ListView mainListView ;  
     private ArrayAdapter<String> listAdapter ;




@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_map);

    // Look up the AdView as a resource and load a request.
    //AdView adView = (AdView)this.findViewById(R.id.adView);
    //adView.loadAd(new AdRequest());


    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    // Showing status
    if(status!=ConnectionResult.SUCCESS)
    { // Google Play Services are not available
        int requestCode = 10;
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
        dialog.show();

    }
    else 
    {// Google Play Services are available
        // Getting reference to the SupportMapFragment of activity_main.xml
        SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

        if (savedInstanceState == null) {
            // First incarnation of this activity.
            mapFragment.setRetainInstance(true);
        } 
        else 
        {
            // Reincarnated activity. The obtained map is the same map instance in the previous
            // activity life cycle. There is no need to reinitialize it.
            map = mapFragment.getMap();
        }

        setUpMapIfNeeded();
    }
 }

 @Override
 protected void onResume() 
 {
      super.onResume();
      setUpMapIfNeeded();
 }


 public void openBigImage(View v)
     {
        setContentView(R.layout.bigpicture);
     }

bigpicture.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"       
    android:id="@+id/bigpicture"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical">

<fragment
    android:id="@+id/minimap"
    android:layout_width="200px"
    android:layout_height="200px"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    class="com.google.android.gms.maps.SupportMapFragment" />

 <ImageView
    android:id="@+id/badge"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:adjustViewBounds="true" />
 </RelativeLayout> 

Calling setContentView() multiple times worked in other cases, like menu items "about", "settings" etc. Tried to make without setContentView. I've put new Layout to the main.xml and made visibility GONE. OnClick method should change visibility to visible, but again nothing happens. Logcat says "11-25 13:47:28.638: D/GestureDetector(3156): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0" when i'm clicking on linear layout.

Paul Chernenko
  • 696
  • 5
  • 21

3 Answers3

0

Paul, One thing is close the linear layout with /> .I am assuming that you have followed the map tutorials link and passed all the manifest permissions and other requirements. You might have some reasons to use px. Check if map is being created. Also give some height and background color to your badge image and see if something happens.

I tested your code without map fragment and it worked fine. Can you post the error log ?

aNoviceGuy
  • 286
  • 3
  • 10
  • Map works, now i'm adding features, exactly when you click on custon info window another layout must appear. It is only a fragment of code with linear layout to show "OnClick". It is closed with later. – Paul Chernenko Nov 25 '13 at 11:30
  • There are no errors, log only shows that i'm touching the screen and nothing happens. I'm trying not to use setContentView() now. – Paul Chernenko Nov 25 '13 at 11:34
  • After clicking on linearlayout logcat says '11-25 13:42:24.633: D/GestureDetector(797): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0' – Paul Chernenko Nov 25 '13 at 11:43
0

Found. It is a click on InfoWindow, so we should implement onInfoWindowClick. But first we must add map.setOnInfoWindowClickListener(this); in main activity. Main activity must implement OnInfoWindowClickListener. I've added new LinearLayout to the main.xml, made it invisible. Here's code for onInfoWindowClick:

 @Override
public void onInfoWindowClick(Marker marker) {
    LinearLayout secondLL = (LinearLayout) findViewById(R.id.bigpicture);
    int visibility = secondLL.getVisibility();
    if(visibility == View.GONE)
    {
         secondLL.setVisibility(View.VISIBLE);
    }

}
Paul Chernenko
  • 696
  • 5
  • 21
-1

I think you can't use onClick attribute. You have to use setOnClickListener() like that :

LinearLayout layout = (LinearLayout )findViewById(R.id.window);
layout .setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        YourActivity.this.setContentView(R.layout.bigpicture);
    }
});
Maxime
  • 1,332
  • 1
  • 15
  • 43