Load a different form layout on spinner selection - java

On opening the activity, the user chooses an option from a spinner. I have the spinner working and I can successfully read the onItemSelected listener from the spinner. However, after the user clicks the spinner, I'd like to load a different form layout below the spinner; based on their choice. Can I store the different layouts in the same XML file, and then just call them based on their ID?

You can use different layout on a layout.See how to Inflate Layout.See this link for android layout Inflate.In your main layout create two linearLayout.add your spinner in the first layout.And in the second layout add various layout according to your choice using LayoutInflater

Related

show another xml by clicking a button without creating another activity

Is there any way to avoid creating another activity to show an xml page from another xml by clicking a button.
The same activity must be used instead of creating another one in this case.
You can inflate your XML View to one of your Layout in Activity's xml Layout file.
1. Create Blank RelativeLayout and set visibility invisible.
2. On your action performed set Visibility true and inflate view to Relative layout like below code.
RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.child, null);
item.addView(child);
Welcome to the Android world , check this out
Fragment

android GridView, ListView and WebView in ScrollView

I'm implementing mail application for Android. I need to display mail content in ScrollView. The problem is I also need to display attachment as image backed GridView or ListView. Since it is not recommended to put aScrollable layout in ScrollView, how to organize my layout to have adapter based views inside ScrollView?
how to organize my layout to have adapter based views inside ScrollView?
You don't.
I need to display mail content in ScrollView.
Why? Why not display it in a non-selectable first row of the ListView? That way, it and the rest of the list scroll in unison. Remember that an Adapter can provide different row types, with different layouts, for different rows (via getViewTypeCount() and getItemViewType()). So you can have the first row be the message, with the rest of the rows being attachments and such.
Or, make the mail content scrollable in its own ScrollView, but have the attachments shown separately.

Custom dialog having mutiple editText and spinners in Android?

I am trying to put custom dialog in buttons on click event, and dialog box having multiple textViews and spinners in Android.
How it possible?
Hi check below sample demo app,
http://android-coding.blogspot.in/2011/04/create-custom-dialog-with-edittext.html
Create layouts as whatever you required like multiple edit text or spinner ,
1) create activity and set theme of dialog in manifest.
OR
2) Create class and extend with dialog and use.
you are set layouts as per your require controls.

Android - Dynamically add items to ListView using existing XML layouts?

I have a ListView that I want to dynamically add items to. For the items, I want to use a specific layout that I have defined in XML. How do I go about adding the items to it and have each item use the specific XML layout?
Do I have to create an adapter and jump through all those hoops? There is only a handful of items that I need to display. Each item has a few text views that need to be populated as well as an image that needs to be displayed.
If I go with the Adapter route, I need to basically creating a custom object/class that contains the text for each textview as well as the URL of the image I'm downloading. Seems like way overkill for just displaying a handful of listview items.
Isn't there someway I can just iterate through my items, inflate a view for each and add them to the listview?
you want to use a ScrollView for your purpose. works just like a listview, except the rule is a ScrollView should only have one child layout (that layout would be containing all the items you want to put inside). inflate a layout, then addView(). rinse repeat.
Unfortunately you do have to create an adapter. SimpleAdapter is about as easy as it gets. Here's a nice example that'll have you up and running in a few mins:
http://ykyuen.wordpress.com/2010/01/03/android-simple-listview-using-simpleadapter/
Either you can create an adapter which is really not all that complicated, or you can use a ScrollView with a LinearLayout inside and inflate yourself. Either option is reasonable, depending on your requirements, but inflating yourself and adding the views to the ListView manually isn't one of them. By the description you give, it sounds like you might just want to go the LinearLayout route.
Put a ScrollView with a LinearLayout inside in your main layout XML.
For each child:
Inflate the view for the child item and populate the fields accordingly.
Add the child view to the LinearLayout using addView.

In android how to place components in a listview with items?

I am using a listview with listitems and there is a need for me to add button near each listitem. How can i make it possible.
you need to have your own custom adapter and in that you have to set the layout in the getView() method. Now in the layout file that is the xml file keep the button.

Categories