Hi,
I want to implement form like in the image, dont have idea how they are adding Fields dynamically. Is this a ListView? Expandable List? user can add and remove at runtime. I have checked Expandable List which contains child items. but we define child in array, In the image they add dynamically.
Any guide/link
Thanks
Custom ListView Adapters are often back by Collections, like List, ArrayList, etc. These lists may contain your custom objects, where the Adapter determines what to display based on the object properties. The lists can be managed/altered in typical fashions, like add() remove(), etc.
Do a Google search for "android custom list adapters" to learn more.
Here is an example of dynamically creating list rows with a "plus" buttons to add more rows. Should give you a good start: Dynamically add elements to a listView Android
You can always look at the source of the Android contacts app, as well.
Related
First I have build a simple android application which had only five optios to select. For this purpose I used five Buttons on main Activity. Now I have more than twenty buttons in a ScrollView to select. What is the best way to represent this kind of application (using buttons in a ScrollView? using TabHost? or with some other widget?)
The app look like this now:
Grid View or List View or Recycler View
the Adapter automatically will add buttons with the names you want, something that I did for my upcoming app.
I made a java class called data which has 'data` for my app.
it has an array of images for my GridView.
SO:
Make a class called data
Add a public final static String[] myArray array of your names, or data
Now, whenever you want to access them, use data.myArray
If you want to access one item ,use data.myArray[itemIndex]
Don't forget, indexes are zero based, not 1
Put your button inside a viewHolder class
find the id of the button in the getView if convertView is null & set the holder as a tag
NOTE : after finding the ID of the button, just leave it don't do anything or edit the text, continue reading please.
Use that array with your custom adapter
as
gridView.setAdapter(new myCustomAdapter(parameter1, parameter2,data.myArray);
use this , I just made it yesterday, added array of buttons feature now. You can just learn it or use it or commit changes.
NOTE :
You can make an array of listeners just like any primitive data type, View.OnClickListener[] and name it, initialize it.
Use grid view. it will be easy to show multiple buttons on screen using grid view.
If you are creating a very dynamic list, say, where every row can have a different set of input types plus optional buttons, and the list length is based on another dynamic value, is it better to do this in a list adapter or creating a custom view in a scroll window?
After struggling with list adapters for quite a while now something finally occurred to me- this seems dumb. It seems like I am going through a lot of work keeping track of what spinner is set to what value, which row was clicked and so forth.
For example, say you are showing something like a contacts screen with various details that can be entered about a contact. Some rows will have text inputs (name, address etc), some will have spinners (ie. state, group), some will have checkboxes (like 'favorite' or something). Also, there is an 'add' button that allows you to add another field to edit. Is it worth making this in a list adapter or is it better to populate a custom view, and if the "add" button is clicked, we re-create the custom view, adding a view of the type they want to add?
I hope this is clear.
ListViews (and List Adapters) are meant for data that is to be displayed in mainly similar views. For your example, it is much easier and more natural to have a predefined layout file with the screen and use view visibility so select which views are to be shown. If you need to add views to the screen you can do this dynamically by using findViewById on the layout and then using it's addView method.
Let me know if you need more clarification or sample code...
I need to implement listview with multiple headers and list item under each header are different.
For example the first header name is weather, under this header, each list item has city name and current temprature.
The second header name is contact, and the each item under this header contains person name, contact number, call icon, message icon etc.
Can anybody know how to implement this in android?
Thanks
Mindus
In order to achieve Multiple header and different layout in a ListView you should use Section ListView
Section is like Header
And you can inflate different layout. Smiler example is given here Link
For Complete Source code go through the below link.
http://amitandroid.blogspot.in/2013/05/android-section-listview.html
As far as I know ListView can have multiple headers, but you can't locate them at the postion you want.The all will be located at the top http://developer.android.com/reference/android/widget/HeaderViewListAdapter.html
I advice you to use separators.Also this can help you https://github.com/commonsguy/cwac-merge
With this MergeAdapter you can insert adapters and views in whatever order you want and then present them all as a single adapter to a listview and consequently you can achieve multiple headers simulataion.
you will have to make different layouts for each type of cell (separate for weather and separate for contacts) , you will have to override getView method of list view as well and upon need, just set your desired view for cell to update it.
Thanks guys, Finally i got it with two different listview with separate linearlayouts. And use textview as a header in each linear layout.
I would suggest not using a straight linear layout for entire sections.
For headers and lists, I would recommend a MergedAdapter, https://github.com/commonsguy/cwac-merge, either that or roll your own.
For multiple cell layout types, this is support in the listviewadapter with the following methods from BaseAdapter
getItemViewType(int position)
getViewTypeCount()
This allows you to specify how many different types of layout are in use and then recycle the layouts appropriately.
I am doing android application. In That I want to display a List of podcast urls like shown in the Image. In this I also share this url into FB, twitter and etc and also the user clicks the arrow symbol I want to forward to that podcast url.
I am having those values in separate arraylist (i.e. "4353,3424" as a arraylist and "567567, 234234" as a another arraylist likewise). So how can I display these values like shown in the attached image. Can anyone help me how to proceed to display like this?
I'd recommend you had a look at some of the tutorials on how to implement your own custom ListView.
An example can be found here: http://www.thepcwizard.in/2012/09/android-creating-custom-listview-for.html
Also I'd recommend you create a custom class for holding the different informations in every row of the ListView. When doing it like this you can have one single List<MyCustomObject> holding all informations and then when a row is clicked, you simple get the item from the List<MyCustomObject> and get the specific property of the custom object and act accordingly.
EDIT: Small example of how to add onClickListener to a sub-view of the row:
Inside the getView method of the custom Adapter you can use setOnClickListener to the views, you'd like to respond to clicks. For instance:
myImageView.setOnClickListener(this);
Then let your custom Adapter implement the interface OnClickListener and act accordingly to the clicks.
Another way would also be to add a Share Intent to the different images, like in this example:
http://sudarmuthu.com/blog/sharing-content-in-android-using-action_send-intent
You would need to create a custom ArrayAdapter to populate a ListView from this objects the way you want.
The advantage of this technic is that you gain a Views recycle mechanism that will recycle the Views inside you ListView in order to spend less memory.
In Short you would have to:
1. Create an object that represents your data for a single row.
2. Create an ArrayList of those objects.
3. Create a layout that contains a ListView or add a ListView to you main layout using code.
4. Create a layout of a single row.
5. Create a ViewHolder that will represent the visual aspect of you data row from the stand point of Views.
6. Create a custom ArrayAdapter that will populate the rows according to you needs.
7. Finally assign this ArrayAdapter to your ListView in onCreate.
You can get an Idea of how to implement this by reading this blog post I wrote:
Create a Custom ArrayAdapter
I have build an application in android. This app needs to display a list of text, but the list of text increase continuously. It means user can see increased list of text. Each text is separated by a horizontal row. It looks like google market when market try to show list of applications. How can i do in this situation ?
You didn't mention where the data came from but let's suppose that you have an ArrayList of your model Text.
Steps:
Add a ListView to your layout
Extend ArrayAdapter
Set this new adapter to your ListView
Modify the array adding/removing new stuff
Notify the ListView that the data has changed using the adapter's notifyDataSetChanged() method.