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
Related
I searched allover but couldn't find any clear answer. I have a ListView declared in A customView and I would like to open another ListView when clicking on an Item.
I managed to do that by changing the adapter each time I click on an item on the Main ListView and show a pseudo new ListView. However this is not a stable solution.
I would like to know how can I instantiate a new listView without using intents or without having to change the adapter each time I want a new list output. I would want to create an entirely new ListView without direct connection to the initial one.
Can you try using ListFragment with FrameLayout in layout file? and just switch fragment when click on list item
I found the solution. I created in the CustomView several LinearLayouts for each listview one root layout. I have also created an individual class for each listView and used the same CustomAdapter and ViewHolder throughout. What I additionally used were interfaces that I declared in each List View class, with a method that tracks the row number. Based on this I implemented all the interfaces in the CustomView and listened to the clicked rows. At last, I then created animation methods and played with the visibilities.
By the way, instead of setting the List views to INVISIBLE i set them to GONE, hence there are quite manny the GPU doesn't need to recalculate the layout bounds.
Hope that helps cheers.
The method that i Place in the customView init() looks like this:
The interface listener must be implemented on "this" context of the CustomView, otherwise NUllPointerException hence the ListView doesn't know where to listen too.
I have a problem with my Android application which I'm developing in C#. I have a ListActivity and an ArrayAdapter and inside ListActivity i have custom views with a TextView and a Button.
This button should start new activities, get the results from the activities (mostly text inputs), and do something in the background, and then update the TextView's text.
I'm using ViewHolder pattern in the ArrayAdapter, and Command Pattern for the background operations.
My problem is that I can't find a way how to update the TextViews inside ArrayAdapter, since I have the results of the activities in the ListActivity. I tried to create an event in ListActivity and subscribed to it inside ArrayAdapter but I think it is not an optimal solution to this problem.
Could you suggest something better implementation to this problem?
Thanks in advance!
I have an app using an ScrollView and it loads a lot of images.
I decided to change to ListView. I saw that to use ListView, my class must extend ListActivity.
My current class does a lot of things, like inserting in database, updating, etc.
So, should I create a new classe just for the ListView? Can I just say that my current class now extends ListActivity?
In case I need to create a separate class just for the ListView, how do I use it in my current class?
Any help is appreciated!
Best regards
Your class doesn't necessary have to extend ListActivity you could use a simple Activity with a ListView element in it's layout. To use your existing activity just replace the current ScrollView element with a ListView element. Then retrieve this element in onCreate() and set its adapter that will map the images to the ListView rows. You will have to make your own custom adapter to show the images.
ListActivity is just a sub-class of Activity.
Its the same but it allows you to have utility methods such as setListAdapter() and also manages stuff like showing a placeholder when there is nothing in the list by looking for #android:id/empty in your inflated layout.
Using ListActivity it helps to manage the List that with the id of #android:id/list. It works just as well managing your own list without the ListActivity,it wont break your current code if used correctly just have to make an adapter for the list..
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.
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!