Buttons showed when a marker is clicked in a MapsActivity in Android - java

I'm developing a simple app that uses one MapsActivity. Since I'm new to Android app developing, I have some doubts.
I've seen that when you click to a marker you've previously added, two buttons show up on the inferior right corner. One is to open Google Maps itself, and the other to open Google Maps with a route to the marker.
What are the activities that those two buttons start? I would just like to remove those two default buttons and make one myself with a text like "Show route", the problem is that I don't know how to acces to those two buttons (so I can remove them) and the activities they manage.
Thanks.

Try this:
mMap.getUiSettings().setMapToolbarEnabled(false);
Edit:
Please note that your mMap variable has to be initialized, otherwise you will get a null pointer exception

Related

how to use fragments to create an overlay effect for an add contact function when a button is pressed

I'm trying to create an overlay that is triggered when a button is pressed. This overlay is supposed to allow the user to add their contact and I was wondering how can I use fragments to get this effect like you can see in this mockup.
I am in a dilemna over using fragments is the right choice. My reasoning being that I only need to have it do one task that is adding contacts, and thus I do not need a whole activity.
This is what I have on the main activity right now
I would really appreciate any help on understanding how to make this work.
You can use a DialogFragment.
It behaves like a normal Fragment for the most part. Here is a guide for a basic implementation https://guides.codepath.com/android/using-dialogfragment
They appear automatically in the center of the screen. To get it a bit lower like in your mockup you can change where it is in the window. Here is an answer showing such Position of DialogFragment in Android

Multiple pages with different functionality

I am currently working on a layout project for Smartphones and tablets in Eclipse (Java). I followed the instructions on the developers site, how to create different layouts for different screens and this works just fine.
The problem I am having is that I want different buttons in different layouts, when I remove 1 button from, lets say my Smartphone version but I want to use it in my tablet version, the Smartphone version crashes because in the MainActivity.java it calls for a button he can't find.
I tried to solve the problem by creating a different mainActivity page for every device, but I cant figure out wether it is possible to create multiple launchpages with different names in the AndroidManifest depending on the device that is currently used.
Regards.
If its a different button but a button still exists, then you could just initialize the variable to reference that other button and the code should still work.
If the behaviour is not the same, then you could have a base class which contains most of the common code, and 2 subclasses one for each layout.
The problem is you might be giving different id for different buttons in different layout File. Change the drawable/style as per the layout-folder but keep the id same for all the buttons in difefrent layouts.
I recommend you using AndroidQuery for this purpose. It support multiple ui implementation in one simple code.
public void renderContent(Content content, View view) {
//this is a phone!
//this view exists
aq.id(R.id.textInMobileLayoutOnly).text("Welcome to my Mobile App!");
//this button exist in tablet layout only, but it's ok
//AQuery will ignore all the operations on this view
aq.id(R.id.butttonInTabletOnly).text("Open a new tab!");
}

Changing views/activity in Android

I am a newbie in Android and currently I am designing an application where I have faced a big problem with changing views. I have 3 classes, each one for a different screen. I use a button to change pages but it does not seem to work. Every time I move to the next screen, the variables methods etc of the 2nd screen are located in a different class. Can you please show me the simplest way to do this? Thank you.
Place each screen in different Activity. Start respective activities according to button presses. To pass data between activities use Intent.
Activity Reference
Intent Reference
Simple Example for Activities and Intents

How to implement an activity into another?

I don't know if it's a dumb question because it is one of my first apps.. but if that's the case, please also explain why!
If I create a Tab-Based Activity-Structure, I get nearly what I am asking for but only for Tabs. What I want is generally opening a second or even third activity in one main-activity which contains the main-interface.
Example: I have a Title-Bar and a little icon at the bottom-left corner for some reason during the whole app runtime. Now: How can I control them with the main activity and open at the same time some other activities/views into the existing interface? It should then be shown below the title bar and lying underneath the little icon (the icon is not really important, just fictional). Also it would be nice if I could add some fade in effects to these embedded activities/views. Is that somehow possible?
I currently only know, how to open activities each over another filling the whole screen, except in the case of tabs... maybe I only haven't inspected the tab structure enough.. however, I would be delighted about each answer!
Regards
What you are looking for, are Fragments.
Fragments can be used to fill a part of the screen, while doing something else entirely in a different one.
In your example you can create a main activity that contains two Fragments. One Fragment controls the title bar, the other one controls the main content area.
By replacing the current Fragment in your content area with a different one on the press of a button, you can achieve the behavior you are looking for. At least, that's how I did it in an app of mine containing a main content area and a music player. The music player stays in place while the main content changes.
Sadly I can't provide any example code right now, but here is a tutorialthat should help you get started:
Android User Interface Design: Working With Fragments

Help with code layout

I hope I can explain this properly.
I'm making an android app that, when you open it, it connects to a JSON server, pulls down the data (GPS coords) and dynamically creates a "menu" based on what it received (View1). This will consist of a few buttons, which when clicked, will load a MapView (View2) with the coords gotten from the JSON represented as markers on the map.
I start off with setContentView(R.layout.menu) then get the data, onbuttonClick I load setContentView(R.layout.map) and draw the markers. The problem is, I have an onLocationChangedListener that goes through the code to set up the menu initially. When it tries to build the menu when the mapView is open, I get a force close. Unfortunately, this code also updates the user location and the locations of the overlays and re-draws the map.
My question is: Can I do a check on a layout to say something like if (isActive) so that I can perform actions only if the current view is in focus?
OR should I scrap the whole thing and start again with a better layout? (Suggestions welcome)
Summary::: I have 2 views (menu,map). Need access to same data across both. Currently works with setContentView() but gives me a Force Close when actions are performed on inactive view.
If I understand correctly, you are using setContentView(someLayoutId) to change each time what the Activity is displaying. This is not the way android apps usually work. When you retrieve a resource, you need a root element to reference it, that's why you get the exceptions when the View is not "active".
You have several other options to evaluate:
Create a new MapActivity to show the map
Create a TabActivity and add the map as a new tab
Use a ViewSwitcher to decide whether to show the map or not.

Categories

Resources