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.
Related
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'm working on creating a swipe-to-dismiss list view adapter. My basic methodology is to wrap the list item's view as the second view in a ViewPager and provide the necessary callbacks in the item change listener of the ViewPager. Through much pain I've got the View recycler working as intended, as well as ViewHolder and ViewBinder patterns implemented. I even managed to keep the ListView from taking over the touch events while the ViewPager is being scrolled without having to make a custom subclass of ListView (I can do it all from the Adapter).
Where I'm running into trouble is getting the selector and the OnItemClickListener to work. After looking at ListView's source it seemed that by overriding the ViewPager's hasFocusable() method to always return false (later on I'll pull this value from the child view) these things should have been reenabled. Unfortunately this is not the case. I've tried the setDecendantFocusability() workaround and I'm still stuck.
I'd like to avoid having to extend ListView if possible to provide the greatest amount of modularity. For similar reasons I don't want to add the selector to the ViewPager's background (if the dev changes the ListView's selector this wouldn't be reflected). Essentially I'm looking to make the ViewPager code transparent between the ListView and child View. Any ideas?
You are saying that you are making each list item a view pager, so that you can implement swiping to delete? If so... no no, this is not what view pager is for. First sorry it is just not intended to be used as an item in a list. Second it is for switching between views, not swiping to delete.
Unfortunately we don't have a sample code to show how to do this, but you can look at the platform's implementation of the notification pane or recent apps to get some ideas.
i have to make a listview in which there are two elements to be displayed vertically.
i know that to use the default adapter given with android there can only be one array and one text resource...ie if i am using android.R.layout.simple_list_view then there is only one text resource.
To make a custom Listview i am doing the following:
making a xml layout file for each element of the listview
extending a custom adapter class which extends the baseadapter
in the getview method of the custom adapter class i am inflating the view for each element and then returning with the info i want the listview element to have from an array which i have passed as a constructor to the custom adapter class.
this seems very tedious because there are several instances where i have to make listview where sometimes there are three text elements in each listview element and sometimes 2 text elements in each listview element.
is there an easier way to do the above.
thank you in advance.
With such simple layout, I'd suggest you to just use a LinearLayout and 2-3 TextViews (or any view you need, even an horizontal LinearLayout). Nothing will beat that simplicity. There's no need for a ListView in that case.
You could consider creating a generic, reusable ListView layout file that is loaded up with all the various elements you need (which, hopefully is a concise few). You could default as many of those elements in the layout XML file with android:visible="false" and then programmatically toggle the visibility.
Why can't you just reuse the adapter? It's got plenty of loading/unloading methods associated with it.
Yes, what Aleadam is saying; if you only have a couple of things why use a ListView? TextView would seem a much quicker way to prototype data display!
I want to create list view just like this: http://dl.maximumpc.com/galleries/androidpower/Alarm_full.jpg
I need to create view like on second and fourth screens. As for fourth screen, it seems that each row has it's own layout...
I've searched Internet and even downloaded alarm source code from git repository, but it doesn't contains what I want. Any help would be useful. Thanks!
The second screen is pretty straightforward. It's basically a RelativeLayout with a full-width button at the top and a listview. The listview items will use a custom layout e.g. a RelativeLayout with a Button showing the time, a TextView to show the description, a TextView to show the selected days and a CheckBox to indicate selection. The fourth screen looks like a preference activity which can be built up from an xml file and/or custom preferences.
Yes, as John J Smith said, it's not very complicated. And i'm sure there are many articles on Internet about how to build a custom list view(at least there're many in China).
And here is a general way to do this:
To custom a list view, follow these ways in general:
1. create your own list adapter, usually extends BaseAdapter, write getView method etc;
2. bind your adapter to a list view;
3. write a layout file implements your list view item, and bind data in your adapter.
Especially, if your custom list view item has a button/checkbox/etc, you'll need more work.
My app used to use a standard ListView, and registerForContextMenu(getListView()) and everything worked just fine.
I needed to change my app to accommodate nested lists so I replaced the ListView with ExpandableListView. I changed the Activity to ExpandableListActivity. I also changed my adapter to a tree adapter and implemented a custom view class to populate the list with (based on a FrameLayout view).
Suddenly my context menus stopped working and I can't figure out why. I can't long click on any of my list items and I'm completely stuck on where to start looking.
Probably another view then your listitems receives the longclick.
I would add OnLongClickListener to all views and create log what listener gets triggered by a longclick.
Otherwise it might help to see something from your code to spot an error.