I think you have the first step done. To me, if you can visualize and draw out what you want, the next step is to just dive head first into the code. You will learn, just don't be afraid to do some internet searches first.
First of all, I always recommend that new Android developers look at the Android lifecycle to understand what happens where. For your application, you should understand what an Activity
is, and what happens in onCreate()
. Do some reading and try to grasp what an Android Activity is.
Next, you should look at working with Android Layouts. This will help you put something on your screen. By default, a basic layout.xml file is generated when you create a new Android application in Eclipse. Use this as a basic framework for dropping Input Controls on to the screen. The specific "drop-down" functionality you are looking for can be found in the Spinner control.
Once you have a Spinner
on your screen, you can then fill it by creating an Array
of values that you would assign to an ArrayAdapter
. This ArrayAdapter
then gets associated directly to the Spinner
to fill it.
Use the Android Developers site, it is very useful. They have tutorials and sample code in the SDK as well.
This answer should have plenty of terms, links, and direction for you to get started.
Update:
I would like to expand on my answer to be more specific, but I think I need a little more information. For example, are you pulling these names from anywhere specific (ie. the device itself?). Regardless, the names have to be put in the form of some type of array, either a String Array
or an ArrayList
. This is only because that is how ArrayAdapters
work and ArrayAdapters
are what populate Spinner
objects. So I guess what I am trying to say is that regardless of how you get your names, you are going to have to organize them in some type of array to put them into the Spinner
(if you want to keep it simple of course).
Now, once you get the names put into your array and you can click the Spinner
to show them all, you now want to trigger an event that pulls the data you would like to show beneath it. I would recommend doing this in 1 of 2 ways. You can select a name from your Spinner
and then hit a button to initiate a search for the other information you would like to show. This would be a better solution if you are pulling the data on the name from a network resource. If you are pulling the data associated to the name selected from the actual device (either a SQLite DB you configured or an Android system DB), I would just use an onSelectionChanged
listener on your Spinner
. You can do that by using something similar to this answer:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Spinner spinner = (Spinner)findViewById(R.id.mySpinner);
// create your arrayadapter of names and then set it to your spinner
// then add a lister to look for a change
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// update your view with the information for the selected user
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// do something
}
});
}
Once you can register a change in the spinner, you can then just initiate a query to determine what information to display. If you create a custom DB with all of the information associated to names, you have to create your own DB handler. If you pull the information from a network resource, make sure that you put your networking operations in a background thread, or AsyncTask. If you are pulling the information from your Android device (contact records or something), just use Android's build in functions, libraries, and API's. I would try to keep everything localized instead of having to depend on a network connection.
Once you have all of the information, you can dynamically create layouts and add them to your current view or you can just have a single layout that you change occasionally and to show and hide. Both of these solutions are completely reasonable, and I don't believe one is necessarily better then the other. I used to be a fan of just making objects invisible and showing them when I needed them, but I am getting into programmatically creating layouts on the fly when I need them. This seems to be a little more difficult for new Android developers though, so don't feel bad if you have sketchy if/else statements that just show and hide XML layouts.
Anyway, hopefully all of that helps!! Welcome to Android!