I would like to create an ListActivity that's arranged somehow different than a usual list: it should contain, on each list row, multiple selectable items (image buttons to be more precise).
The items will be loaded from a SQLite db using a cursor.
My questions are:
I'm not sure I should use a ListActivity for this functionality. It looks like a List, but with custom design and behavior, so if anybody can suggest any other way to do it..
Assuming I can use a ListActivity, what I can't figure out is how can I do it. All the examples so far refer to list with only one item per row.
Thank you !
Create your custom adapter by
extending BaseAdapter class, So you
can custmize listview howerver you
want. Then palce your image buttons in
each listitem and provide
setOnClickListener for each image
buttons inside the adapter class:
Check out the following post for
coding help
: Custom ListView
Cheers!
Related
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
The app I'm developing is using ActionShercklockBar,
On the main activity (SherlockActivity) I have a bar with a search field,
A ListView (which is to have two entries per row)
and a spinner
the problem is that as I'm starting with android, all the tutorials I've found require that my activity extends from ListActivity
but mine is extending SherlockActivity so I'm a bit confused as to how I can implement the two lines entry
Could anyone point me to a resource on the web or provide some input on this?
Any help is appreciated
You don't have to extend from ListActivity to use a ListView. Just place a ListView in your layout and then set it's ListAdapter in your activity's onCreate method. Here's an example that shows this style of ListView: http://windrealm.org/tutorials/android/android-listview.php
For the 2 line entry per row, you'll want to customize your List, so that you set the layout of each item displayed. Check out the OrderAdapter and the getView method implementation in this example: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
The answer for your question is to use the SherlockListActivity class and in adapter that you provided for your listView, in getView() method you have to create a custom view with two rows. There are a lots of tutorials on the web on how to create a custom item in your list view, so please have a look at that.
But if you will be still confused, write me and I will edit my answer with the real sample code.
I have the same problem as you, I have ActionShercklockBar and ListViews in the main activity.
What I did is to extend from SherlockListActivity in the main activity with a ListAdapter and it works well
I am using this link to create custom listview in my app.
First I want to display listview with 5 items. As I scroll the list it should parse data and load listview for next 5 items.
Listview row contains 5 textviews.
How can I achieve this?
Please help me.
Thanks in advance
I want to display 5 items in single row
That has nothing to do with EndlessAdapter. That has everything to do with the ListAdapter you are putting into the EndlessAdapter. Start by not using EndlessAdapter and getting your list looking the way you want. Then, and only then, add in EndlessAdapter to add more data to the list as the user scrolls.
There are countless examples online of how to create rows in a custom ListAdapter that have more than one thing in them. Here is a free excerpt from my book on how to subclass ArrayAdapter, override getView(), and handle more than one widget in a row. You specifically will want to look at the "Customizing the Adapter" section.
I am trying to make a recipe ListView for food and I want to add imageViews next to items in my list. How can i do that? Thx.
A ListView item can have it's own custom layout.
You have to create your adapter for the ListView. When you create your adapter you can assign your custom layout.
Note: You will have to implement getView() to property set the image+text.
Here you have a sample: Lazy load of images in ListView
Following this tutorial could be a nice idea for you (mainly the second example).
http://www.mkyong.com/android/android-listview-example/
But anyway, you should Google a little bit before asking such a basic question.
I have an object submission which contains some informations which I would like to show in a list view.
For example, in my object I can do this:
submission.firstElement().getDate()
and
submission.firstElement().getTitle()
which returns me a date and a title.
My problem is: how to show those two elements (not only the first's) in a listview (two elements per list item).
I have thinked on a for loop with the submission.size() but I have no idea how to get forward with.
Thank you for your help.
You'll want to look at using a ListView and a ArrayAdapter. You could use a BaseAdapter but I have found a ArrayAdapter more than adequate for displaying a list of custom objects in a ListView.
First create a layout that will be used to show the desired data per row in the ListView. In your case I assume that it will be two TextViews, one showing the title and date.
Once done, create a ListAdapter and in it's constructor give it the layout for the row created above. Once done, use the getView() function to access the layout and populate the TextView's with the object's date and title.
Have a look at the following links:
http://developer.android.com/reference/android/widget/ArrayAdapter.html
http://developer.android.com/reference/android/widget/BaseAdapter.html
http://www.vogella.de/articles/AndroidListView/article.html
EDIT:
Ana, to aid you a bit further use a ListActivity as shown in this Google documentation: http://developer.android.com/reference/android/app/ListActivity.html. In the example given they use a SimpleListAdapter. However, for an ArrayAdapter the constructor is a little simpler:
new ArrayListAdapter(this, R.layout.row_layout, listOfObjects);
When using a ListActivity a layout does not need to be created as by default it includes one.