I am creating views like EditText,RadioButtons checkBoxes etc. dynamically as per the response from web service. Now, I need to get the values of all created views in single HashMap or any Map. How can I do that?
you can use the View.getId() function for that
Related
I want to fetch data from web api and fill in ListView in android. I have already learnt how to call web api and successfully done in my app, but the problem is how to show in my ListView? I want to fill data as in shown in below image.
.
How can I fill as exactly as in image? Which components are used in ListView? If this is not a ListView then which layout is this? I also want to know how can I use above buttons(Overview, matches, Teams, standings ). I want to change the data when I press different buttons. Please share your experiences and suggest me some learning sources.
create a custom java class describing a single Item as an object that will contains a number of variables for storing data that will come from web API.
create a custom layout (list_item.xml) contains two ImageViews and 3 textviews .
store your API data in an Arraylist of type (YourCustomJavaObjectclass).
create a custom Arrayadapter , then inflate the (list_item.xml) inside the getView method and then bind your views with data from the ArrayList.
For more info read this article
https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView
For creating these (Overview, matches, Teams, standings) you have to use ViewPager and FragmentPagerAdapter , for more Read this https://github.com/codepath/android_guides/wiki/ViewPager-with-FragmentPagerAdapter
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.
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 can't use listview because this layout will already requires scrolling. So this leaves me at a problem: how to create my tables.
What I know:
The size of the JSON array
I was going to try to make every cell in XML and do a for loop in the code, but my predicament is that I can't findViewById very well, because the R.id.myId names are difficult to account for, and are integers instead of strings. (probably a problem not as large as I am making it).
So here, I know the server call will return a json array with up to 5 objects in it. How can I populate my view?
I am using a LinearLayout for each row, much like I would be preparing a custom list view in preparation.
Insight appreciated.
Is there a specific reason you need it to be a ListView? If not you could try a LinearLayout with a vertical orientation as the container for your list. Just put the container in your xml and you can programatically add the rows that you generate using addView().
I need to create an activity(view) that shows several lists, for example:
(text)Fruits:
(item)apple
(item)orange
(item)pear
(text)Veges:
(item)Cabbage
(item)Carrot
all data are read from a database, so I cannot determine them and create layout file(xml) for them, what's is the best way to create this? Also, list items are clickable which directs users to another screen.
Thanks!
ListViews are filled with data using Adapters. So, you can use a single layout with a ListView and change adapters depending on what you want to display.
Have a look at Adapter interface.
And if you want to have several ListViews, then in your case I'd use a single ExpandableListView widget with differet groups like Fruits, Veges and so on.
If you have created a database using sqlite already, U can use cursor adapter to fetch the data from your database. Its really simple. try to find out how to fetch data from database and how to insert values into listview using cursor adapter.