How can I display information in the following format? What controls should I use, listView or RecycleView?
Note that the question isn't about this particular activity and how to use it. It's about how to show the information in the same format and how to create the layout for it.
That is a ListView. You would just need a ListAdapter/ArrayAdapter to fill it and that's about it.
You can make exactly the same thing using the layout simple_expandable_list_item_2 in the SimpleAdapter of a ListAdapter (here is how you do it : Displaying kind of static data in ListView)
RecyclerView is of course much better in terms of performance and flexibility. However, ListView is enough in many cases like this one.
Related
This is how my screen should look like. The problem for me here is, I should pass User object to adapter and fill those fields with user object fields. How could I know which field to update if I create child layout with one TextView?
Is it a better idea to create for example DetailsViewHolder, AddressViewHolder, etc? Or I can create details.xml with 6 Edittexts? but I don't think that's a good idea, right?
ListView is best for long lists that may change with time. For your situation I wouldn't recommend using a ListView at all, but rather a simple LinearLayout. It is much easier to work with and gets the job done perfectly. If you need scrolling, just wrap the LinearLayout inside a ScollView.
I'm trying to make a android app with a scrollable list like this one...
When I made this app in iOS, I used a UICollectionView. What`s the best way to make this in android studios?
I tried using a list view, but I can't seem to customize it to my needs?
Any Ideas?
ListView was a great way to start and it is customizable to your needs.
However I would recommend to use RecyclerView which works almost on the same principle as ListView but it is a newer concept in Android. It handles the usage of the ViewHolder pattern for you which makes everything super easy.(With ListView, you would've had to implement your own ViewHolder pattern)
All you need to do is to have the RecyclerView in your activity/fragment as the view to hold your data. Then, the key component is to implement the RecyclerView's Adapter which will handle the inflation and setup of each list item.
Here is a really great and short tutorial to get you started with RecyclerView.
If you're done with that here is a bit more advanced video material on RecyclerView from Dave Smith explaining a lot of ways on how to understand and use RecyclerView in your apps.
A ListView fed by an ArrayAdapter of custom objects can do the job.
You might have a class that contains the text and the image of a single item.
Then you can create an ArrayList with items of that class, where you put in all the data.
This ArrayList can be used as dataset for a custom ArrayAdapter, which overrides the getView()-method.
The getView()-method must inflate the xml-layout for each item and attach the data from the ArrayList to the inflated view.
You might want to implement the Viewholder-pattern to achieve a good performance and avoid unnecessary inflations and getViewByID()-calls.
You can also use the new CardView, which can make it a lot easier, since it is made for the new material design in android 5, which looks similar to your item list.
I am currently making an android application which need to present a lot of information from different arrays. On each horizontal line there's gonna be four different texts and then I need to be able to scroll through all information displayed. I know ListView is one way to go, problem is I dont know how to use four text views horizontally in a ListView. Any tips or help to get the best way to present the information would be grealy appreciated.
Basically like this:
You have to extend ArrayAdapter and override getView() of Array Adapter.
The page layout is like:
An header image first
a table or list with one record each line
for each record, it has an image and 2 text view
how can I design this layout and populate the data dynamically, e.g. via web download or an data file(xml/text format)?
I can't figure out how the binding works and should I use a table layout with table row or just list view with some customizations?
Actually, this is going to be a broad question because you are asking about to fetch data from web and also need to customize the listview to display data.
To fetch data from Web: You haven't mentioned whether it is SOAP or RESTful webservice? Also what you will receive in response i.e. XML or JSON? For best, i would suggest RESTful with JSON.
To customize ListView: I can give you answer for customizing ListView, for that you can create a custom adapter class by extending BaseAdapter, implement the onView() method with inflation of custom row layout file (1 ImageView + 2 TextViews), check this: Android custom adapter for ListView
The page layout is... it has an image and 2 text view.
Elaborating on jitendra's answer: Yes, a ListView seems ideal for this set up. A TableView is doable, but is really more ideal for a rows/columns structure and that does not sound like what you need.
How can I design this layout ... ?
You would use the android XML to name and style the elements. The best practice is to make a layout file for the screen containing the list itself. Make a second layout file to house a generic record. In other words, you typically design the record separately from the list and its containers. There are several great tutorial on Layouts on the Android Developer's website.
How can I... populate the data dynamically?
There are two parts to this question. First, in code you will need an Adapter of some kind to convert the Data to the actual Views. The ListView will be linked to the Adapter. The Adapter will inflate the Layout XML that you create for the Record. Different Adapters have different guidelines for customizing the Views. As mentioned by Paresh, a BaseAdapter is a great class, but you really should look at the different Adapters provided and see if they already meet your need.
Second, to get the data...1) from the web depends a lot on your web server and how it distributes data. Without more information, you are unlikely to get any solid answers. We can only make recommendations. 2) If you are going via a data file, things change considerably. You can make an Array of objects from a custom Class designed around your data. If you need Sorting, a Tree might be better. If each record has a unique key, a Set or List might do you well. Based on your question, I find myself assuming that you are unfamiliar with Android development, so I would recommend a datafile loaded into an Array with an ArrayAdapter. This will at least help you get a little more familiar with your own project and how it relates to the Android environment.
I can't figure out how the binding works
Unfortunately, it depends on your View and its Adapter. A CursorAdapter does most of its data binding in the bindView() method of the Adapter, but inflates the View in the getView() method. A BaseAdapter does this in the onView() method. If you need to get more familiar with Adapters and their capabilities, read the Android Developer Resources. They have great samples and code. Also, do a search there for "custom adapter" and you will be linked to a ton of other tutorials.
At this point, I recommend strongly, two actions for you. 1) Make a few decisions. Either you get the data from the web or a data file. If you want to do the other later, great. Get a handle on one, that way we can help you more effectively. 2) Use both Google and Android Developer Resources search functionality with the phrases that define your project. If you add the word tutorial or example, you'll be sure to find plenty to help you make those decisions so that we can tailor a solution that meets your needs.
Hope this helps!
FuzzicalLogic
According to your requirements ListView would be good, and you would need to use adapter to bind data with view.
Please read about listview and adapter to implement these.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#drawable/img_list_background_repeater"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/empty_category"/>
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
No one will give you all java class and xml both.
You frame a xml. Then using adapter try to implent data to the list view.
If then you have any problem, provide your code. Then that can be solved.
I need to create an activty that will show an information table. The problem is that I want to display the information like the following image. Each row has to be like:
I dont really control the layouts yet... so if someone can guide me a little I would be really appreciated.
All of this has to be in code.
Thanks!
It sounds you you want to make a list with custom list items.
Typical approach would be to use a ListView with a custom adapter. You can derive an adapter from, say, ArrayAdapter and override its getView. There, you can use LayoutInflater.inflate to load an XML layout for the list item, and populate it with whatever data. If you really must do it "all in code", however, you can do things like new RelativeLayout() and new TextView() and add them to the parent view in this method. As for the layout itself, a RelativeLayout most likely works best to arrange everything.
Here is an example of how it all fits together.