more than one list item in each list activity? - android

I have a program that I would like to display the name and house number of a group of people. This information is being picked up from a web server and is all sorted (xml format) but I wanted it to be displayed in a ListView with the two different pieces of information in a single list item. When getting the information from the server there may be 3 people there may be 30 so a list view where it extends with the amount of information there is is essential. Any ideas?

You would create a ListView and set your own customized ListAdapter that will display the two pieces of information you need in a single list item

Consider using an ExpandableListView it allows you to have custom "sub-data" under each list item.

Related

Displaying unknown amount of data to screen

I have a sqlite database which contains multiple messages.
Each message has a
Title
Body
Importance level (0/1/2)
Possible calander _id
I want to display them to the screen in a scrollable list. Each list item can be clicked on which will then start another activity to edit the message.
I don't want direct code on how to do it, I'd prefer suggestions on how to do it so I can learn myself. If I need to give any extra info please ask.
You need to use adapter in your case CursorAdapter would be appropriate. There are many tutorials on internet about CursorAdapter and using it alongside with SQLite:
http://www.vogella.com/tutorials/AndroidSQLite/article.html
https://coderwall.com/p/fmavhg/android-cursoradapter-with-custom-layout-and-how-to-use-it
A general note about Adapters is that they are a mean to transfer your data to appropriate View so you can populate your ListView, GridView, ... with the customized data. But this need a whole tutorial. You can also look to see how to work with different type of views which allow to be populated with Adapters.

Collapsible Master Detail preferably using ListView

I need to show Product list (perhaps some kind of ListView) and be able to display product details (could be more than 3/4 items and a place order button) when a product is clicked.
I have seen similar Accordion behavior but the expandable items are just single list items in my case I need to show multiple attributes of the product.
One way is to build a string combining all product attributes i need to display and bind to list. What are my other options?
I am relatively new to Android.
Note: I don't have enough reputation to upload an image/mockup.

How to use a single layout for displaying different information?

I want to use a single layout for displaying different information.
Ihave a list view. When the user selects a item from the list view it should open the layout for that list item. List view contains the name and image of the entity.In the layout it should display all the other information. This single layout has to be used for displaying the information for all the entity of the list view as per the users selection.
Bst way to picturize it is the google play store. we have a list and according to our choice the same layout is used for displaying the information for all applications..
in the list view,layout the data will be fetched from internet.
pls help..
You are basically looking for a master detail flow i guess ...
Check THIS LINK which is exactly similar to what you want ... I think the selected answer here applies to you to your question too.
You just need to do it throught your java code i dont know what exactly you want to change so i cant provide a code but you may easly find some in this website. From a quick search i found this : Editing data in a List View item and it seems to be what you want.

how i get the contact list in multiselect or checklist view?

i need to know how list the contacts of phonebook in a check box list to select more than 1 contact at the same time, because i need it to take the checked phone numbers and send to a multi-contact list sms message
This is a very broad/long question. I've done this for one of my applications, so I can outline the steps for you and give you pointers.
Getting the Phone Numbers
You'll need to interact with the Contacts API. More specifically, ContactsContract.
http://dev.schmid.pro/android/get-contacts-on-android-2-0
How to read contacts on Android 2.0
It's probably best to put the data in an ArrayList.
Displaying
You can use a multi-select listview, which is fairly easy to implement
Or
If you are set on creating a listview with checkboxes, you'll have to create a custom adapter so that you can control the clicking of the checkbox, textview, entire row, etc.
http://windrealm.org/tutorials/android/listview-with-checkboxes-without-listactivity.php
Custom adapters are more complex than using the ListView, however, they are powerful and useful and I'd suggest learning them anyways.
You don't need a check box list, but a List View with proper setting.
if you set the choiceMode to either multipleChoice or multipleChoiceModal (3.0+) it automatically render the lists items with a check box on right. User getCheckedItemPositions() to access the checked items.

Best practice on connecting Activities

I'm writing my first Android app and want to pick up good coding practices. I have an Activity which contains a 2-column grid of all the data items available in the app (listActivity). There's an Activity to create a new data item (createActivity), which is triggered from the listActivity. Now, when the createActivity finishes, what is the best way to handle this situation with respect to the following:
Should the createActivity store the new data item in the permanent storage and return only the ID of the newly created item to the listActivity OR should it return all the data fields of the item as putExtras() of the returnIntent?
Should the listActivity 'repaint' the entire data view or should it simply append the newly created data item dynamically? Will the answer to this question change if the listActivity also has to handle delete & edit events? What if the list view is NOT a 2-column grid but a single column list?
Should the createActivity store the new data item in the permanent storage and return only the ID of the newly created item to the listActivity OR should it return all the data fields of the item as putExtras() of the returnIntent?
That depends on what your listActivity needs to know about the new item. Generally saving the data in storage and only sending back the ID should be enough - based on my answer to some of your following questions. You might also need some indicator of the action that has been performed (Create, edit or delete).
Should the listActivity 'repaint' the entire data view or should it simply append the newly created data item dynamically?
Yes, if something in the underlying Adapters data set has changed a repaint is most probably needed (or at least calling notifyDataSetChanged() on the Adapter). If the order of the items in the list does not matter, you could just append the item to the list - but I still recommend that you save it in storage and then retrieve it when you want to add it to the Adapter. This is also why you would only need to pass the ID around. Also in order to append you would need some way of knowing if the last listitem has one or two columns filled.
Will the answer to this question change if the listActivity also has to handle delete & edit events?
The edit functionality is basicly the same as created (except the fields have values when you open the edit view). If you delete an item from the list a full repaint of the list is probably the best thing to do, as to not confuse the order of the items.
What if the list view is NOT a 2-column grid but a single column list?
Appending would be easier - but there is not much difference. In a single column list you might be able to avoid some full repaints that would be needed in a 2-column list - though I don't think it will make much difference.

Categories

Resources