Android Complex View: manually create or using layout xml file? - android

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.

Related

Android most efficient Table Layout

So I have a few arrays of data I would like to display in an activity without having like 15 text views with unique ids. Is there a code efficient way to make a Table layout or something like it where I could feed in data and it would automatically place it in there respective text views? Thanks!
I think you can achieve that by using RecyclerView (with a GridLayoutManager). Have a look at this answer.
If there are only TextViews and you don't want a specific layout you can use SimpleAdapter, if you want to modify the layout you have to extend RecycleView.Adapter (there is an example in the answer above).
You can add/remove items into/from a List and use DiffUtil that
can calculate the difference between two lists and output a list of update operations that converts the first list into the second one.
There are a lot of tutorials about using this class. Have a look here or here.
Or you can use the notifyItemChanged() method:
If the list needs an update, call a notification method on the
RecyclerView.Adapter object, such as notifyItemChanged(). The layout
manager then rebinds any affected view holders, allowing their data to
be updated.
LE: There are some libraries available. Here is a list:
https://github.com/evrencoskun/TableView
https://github.com/HYY-yu/TableRecyclerView
https://github.com/Cleveroad/AdaptiveTableLayout
https://github.com/celerysoft/TableFixHeaders

How to fill data from web api into Custom listView in android

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

Android display multiple lists values

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

Android tabluar data from database

I want to show all the data from the database in a View. addview to the layout is a good idea. But as I don't know the no. of data, I cann't create required no. of textview, and i cann't add a single textview multiple number of time. How can I solve this problem?
But as I don't know the no. of data, I cann't create required no. of textview, and i cann't add a single textview multiple number of time.
You don't need to create TextView multiple times, it would lead to more complex application.
Rather I would suggest you shold create a simple or custom ListView using simple or custom ArrayAdapter or BaseAdapter or CursorAdapteraccordingly your needs.
Refer this: Getting Stored Data from my Database into ListView
Just read this article to learn how to get info from the database using CRUD methodology:
http://knightswhocode.com/wordpress/?p=14
Create a list of items taken from the database. Then create a ListView with adapter using this list.

Adding from 2 databases to a listView row

Can I add data 2 from different databases into each row of a ListView in Android?
I have a vendor app and I want to add data from one standard items list table and one daily table to the list view.
Yes, but you won't be able to use the CursorAdapters implementation easily. I would put all data you need inside an array, and then you can write your own BaseAdapter or use an implementation of ArrayAdapter.
You might also want to checkout Commonswares CWAC-MergeAdapter maybe it is of use for your problem. It is meant to provide you an easy way of handling multiple data sources and views for display in one ListView.

Categories

Resources