Android : What Is Best Way To Do Multiple Listviews
May 15, 2010
I am writing a software that i have to drill down on content a lot. For example when the program starts a listview is displayed. When user clicks on an item, then a second listview must be displayed. For example:
Select Continent > Select Country > Select State > Select City > Select Address
What is the best way to do this (less memory, faster, easier to code etc)? To create multiple listviews with multiple adapters? Or 1 listview with multiple Adapters? Lists are loaded from an external XML File.
So far i am creating a new adapter and setting it to the listview. How do i create a second listview and after clicking on 1st listview displaying the second one, with animation. Any examples? Extend my class to ListActivity or Activity?
View 2 Replies
Nov 7, 2010
I am not very familiar with android coding so try to help me on a easy way.
The problem:
I have 2 Listviews and a onClick event handler.
How can i find out on which listview the user currently clicked?
public void onListItemClick(ListView l, View v, int position, long id) {
'Approach: if listview1 is clicked then FUNCTION1() else FUNCTION2()'}
View 1 Replies
View Related
Aug 5, 2010
I have a ListView on my ListActivity and I'd like the rows of the ListView to be 1 of 3 different layouts. The first item in my list is always going to use layout A, the second item in my list is always going to use layout B, and all subsequent items are going to use layout C.
Here is my getView function: Code...
R.id.label1 and R.id.label2 are TextViews on R.layout.layout_A. However, txtLabel1 and txtLabel2 are null after trying to set them. Why?
I stepped through this code in the debugger and it inflated the correct layout (R.layout.layout_A) and fell into the correct case below to set the R.id.label1 and R.id.label2 text. Also, if there is a better way to do this, please let me know.
View 1 Replies
View Related
Apr 5, 2010
I want to have multiple listviews in single activity. But only one listview should be displayed at one time. The listviews will be loaded dynamically. So, how can I fill all the four listviews at the same time and display only one?
View 4 Replies
View Related
Oct 29, 2010
I have been trying to get a specific layout for more than two days now and really struck with it, what am trying to achieve is: To have a layout like the following
LISTVIEW A
VIEW
LISTVIEW B
VIEW
LISTVIEW C
(VIEWS are basically for headers) Can any one help to sort out this task?
View 1 Replies
View Related
Mar 23, 2009
I want to have multiple listviews in my activity. Every listview will have a different adapter and every item in the listview must be clickable (other actions for every listview).
So my problem now is that I can't create multiple clickable listviews. I have one listview like this <ListView android:id="@android:id/ list".. and the other listview looks like this <ListView android:id="@+id/ flightList"
The first listview looks like this in my activity hotelList = (ListView)findViewById(android.R.id.list);
the second: listView = (ListView) findViewById(R.id.flightList);
I can click on the first list and it does what it has to do, but i cant do anything with the second list.. probably because it hasn't the android:id/list declaration. does someone knows how I can solve this problem or other suggestions how I can get multiple lists in 1 activity.
View 25 Replies
View Related
Apr 4, 2010
I have a RelativeLayout with different elements. I was planning to have two ListViews on it, but I have noticed there are some problems with scrolling. Since each ListView only shows a maximum of 5 rows should I try to make some kind of custom adapter to merge those ListViews? Or is it better to replace the ListView with a LinearLayout/RelativeLayout and add the rows as I get them manually? (like the first answer in here: http://stackoverflow.com/questions/1778485/android-listview-display-all-available-items-without-scroll-with-static-header ).
Which should be the proper way on doing this? or is there another way? Also, each row will have an OnClickListener.
View 2 Replies
View Related
Mar 16, 2009
So the situation is this, I have a ListView that is embedded in two LinearLayout ViewGroups to form a screen. BaseAdapter.get View() (the implementation of the ListAdapter) is typically called n times (where n is numElements) to render the screen. The problem I have is this set of calls is being repeated for every ViewGroup that the list is contained in...So for a Layout like this:
-LinearLayout --Linearlayout ---ListView
The adapters get View() is being called n*3 times (3 = 1 for the parent LinerarLayout, one for the child LinearLayout and one for the List itself).
This is obviously a problem when the items in the List are expensive to build (even with recycling).
So I'm looking for some guidance on this, as the documentation doesn't seem to note this behavior from what I can see.
A small, basic example of the source is located on my post here http://www.anddev.org/listview_getting_rendered_multiple_times-t5290.... with more details Oswell as a ready made eclipse project(also attached below) if anyone is keen to try it out.
View 6 Replies
View Related
Apr 5, 2010
I want to have multiple listviews in single activity. But only one listview should be displayed at one time. The listviews will be loaded dynamically. So, how can I fill all the four listviews at the same time and display only one.
If anyone knows the solution then please share it over here. I hope to get a quick response.
View 1 Replies
View Related
Oct 18, 2010
I have developed an application which en-composes list views and posted that .apk file in my htc device, the design and alignment everything works fine,but the problem When i am testing in various devices such as Morotolo Droid,Nexus Devices the alignment of Listviews goes wrong, so i planned to use the Layout folder as layout-hdpi,layout-ldpi, and layout-mdpi, for that i changed my manifest file as
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:anyDensity="true" />
Is it right putting android:anyDensity="true",also i used dp instead of dip. I went through this url, but still am not able to get a clear idea in this
http://developer.android.com/guide/practices/screens_support.html. so friends pls tell me(help me) to get clear idea in this and tell what mistakes i have doing. This is my main page xml code frnds.
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_retinav2">
<LinearLayout android:layout_gravity="center" android:foregroundGravity="bottom" android:background="@color/white" android:id="@+id/rl_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<ImageView android:paddingTop="3dp" android:id="@+id/starthideimage" android:layout_width="30dp" android:layout_height="35dp" android:src="@drawable/newback" />
<HorizontalScrollView android:paddingTop="8dp" android:id="@+id/gv"
android:layout_width="wrap_content" android:layout_marginTop="0dp"
android:layout_height="wrap_content" android:background="#ffffff"
android:scrollbars="none" android:layout_weight="1" android:foregroundGravity="bottom">
<LinearLayout android:id="@+id/san_tag" android:layout_width="wrap_content" android:layout_height="wrap_content">
</LinearLayout>
</HorizontalScrollView>
<ImageView android:paddingTop="3dp" android:id="@+id/Endhideimage" android:layout_width="30dp" android:layout_height="35dp" android:src="@drawable/newforward" />
</LinearLayout>
android:id="@android:id/tabs"
android:gravity="bottom"
android:layout_gravity="bottom"
android:listSelector="@color/gray"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> </TabHost>
View 1 Replies
View Related
Sep 7, 2010
I have a ListView, and within each list item I have some TextViews and a CheckBox. When I check a CheckBox and my onCheckedChangeListener fires, everything works as it should. However, random other checkboxes get checked once one is checked. Here is an example.
If I click on the first CheckBox:
8 is checked.
15 is checked.
21 is checked.
27 is checked.
33 is checked.
41 is checked.
Then if I scroll all the way up, none are checked until 6. The next being 13.
View 1 Replies
View Related
Apr 25, 2010
I'm trying to figure out how it's been designed. How it holds its items? How do I get a hold of the scrolling container? How can I know it's exact scrolling position? How can I scroll it to an exact position?
I want to have all the current benefits the ListView provides plus detailed scrolling control... How about animating from x to x+100 scroll position?
Maybe I need to create my own ListView? Where do I begin?
View 5 Replies
View Related
Nov 18, 2009
Firstly, I have found many examples of how to grab data from a db and place it into a list, however this seems to be all for ListActivites.
My list is part of the UI and therefore I can't use a ListActivity because it does not consume the whole screen (or can I?).
This is the UI:
CODE:........
So, from what ive read I need to grab the data from the db, then place it into some sort of array then use an array adapter to fill the list view. Is that correct? If so, is there some sample code because all I can find is code releated to ListActivites.
View 2 Replies
View Related
Aug 13, 2010
Hello, I need to put several listviews inner a LinearLayout. The Listviews should be wrap content to adapt the listview to their items. I need have one only scroll with which I can scroll all the listviews. I know that i can't use a scrollview because the listviews have their own scroll (but i don't need the scrolls of the listviews because i have them in wrap-content). I thought maybe puting the listviews inside the LinearLayout I will hadn't problems with the scrollview, but it didn't work, the LinearLayout was fixed to the screen, the scrollview didn't appear and the listviews ended scrollable. Without the scrollview if i have the list in wrap-content, their shown properly but i haven't any scroll and i can't see the lisviews below the screen. Really i have had this bug for one month and i haven't found any solution,
My code:
CODE:............
JAVA
CODE:...............
How you can see i create the lisviews dinamically and i put indside the layout with a secttion header. if you have some doubt ask me I need find a solution soon.
Sample Image: http://www.freeimagehosting.net/image.php?6dea1468bd.png
View 1 Replies
View Related
Oct 11, 2010
I wish to work with checked list views wherein only one item can be selected at a time. Some queries related to this:
1) Is it advised to work with CheckedTextView as the ListView items, or a combination of CheckBox and TextView?
2) If using CheckedTextView, the text comes first and the checkbox appears on right edge. Is it possible to make the checkbox come on the left of the TextView?
3) How can I make one of the items as checked in onCreate()?
I am using array adapter and calling setAdapter() to populate list.
View 1 Replies
View Related
Aug 16, 2009
I want to show many listviews in one activity. Something like
Textview Listview TextView Listview ..........
Every listview has different type of adapter. For this, I made the activity class like:-
CODE:........................
View 3 Replies
View Related
Apr 20, 2009
Just looking at options for data updating affecting items in a ListView and have hit a few issues/queries.
There seems to only be notifyDataSetChanged() and notifyDataSetInvalidated(). While I could use notifyDataSetChanged() I am most likely in my case to have the scenario where additional data has been added and it seems inefficient to say the data has changed, which can only be resolved by calling getCount() and then getView() for all displayed items where knowing the data has been appended would just require adjusting the scrollbar. Is there some way to achieve something similar to this as the market seems happy populating dynamically in a manner that seems to reflect my desired behaviour (unless it just refreshes it all that fast).
Next question is the situation where the data behind just one item has changed. For instance I may wish to download icons in a background thread, but display available information with a placeholder icon. The best idea I've had so far is to store a map of indexes and views in my adapter which I can check against then call getView directly myself to have the view recycled with the new data. I'd just need additional logic to handle removing the map when the view gets destroyed or when it's recycled in getView. Either a bi-directional map (do we have one of those?) or two maps. Is the above likely to be my best approach or is there something built-in/better to get it done.
View 3 Replies
View Related
Jul 22, 2010
In my app, I have different activities with listviews. The datas come from a server with a REST method, and it's only done once, when I start the application.
The pattern that I'd like to set is to precharge all the listviews with the JSONs that I already have in local, and in parallel, launch a thread that get the new JSONs files with my REST methods, and then update the listviews.
For now, when I start the app, I parse my JSONs files, and build all the lists of objects. I access them later in a static way, from my lists adapters.
So I would like to know the best way to launch this REST thread, and update the listview. Should I use AsyncTask ? A service ? and then, when I update my local JSONs, I have to re-parse them, updates the lists of object, and call in my adapters NotifyDataChanged ?
View 2 Replies
View Related
Mar 22, 2010
Can I have two ListViews on a single ListActivity? I have built the xml file easy enough, but the code around ListActivity, setListAdapter(), getListView() and the like, all seem to be designed around one ListView per activity. How to get 2 ListViews in one screen?
View 3 Replies
View Related
Nov 8, 2010
I'm not looking for exact code here, just a direction on what to look for and what I should be reading about so I can figure this out. I have a layout that I would like to remain static, with only the listview changing depending on what's selected from the list. I've reloaded data in the list, but I would like the fancy transition animations between choices, and would like the app to go to the previous menu when pressing back.
Someone suggested using a viewswitcher, which seems like it'd be great, but I am still unsure about how to fill a listview in a layout with a regular row layout, then on selection do an animated transition to a custom row. Also, it seems the viewswitcher is limited to two views, so it may be a limitation when I want to go a few menus deeper. Preferably, I'd like to put each menu in it's own class so that I can handle filling it in that class, if possible...
View 1 Replies
View Related
Mar 25, 2009
I am trying to design a UI which utlizes two ListViews on the screen at the same time. Is this possible ?
So here is a quick example of how I was intending to do this.
1) Create an XML which positions 2 ListViews one onto of the other each ListView having there own ID
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="198px"
View 5 Replies
View Related
Apr 18, 2010
I guess my previous question wasn't clear enough ( http://stackoverflow.com/questions/2549585/android-failed-to-setcontentview-when-switching-to-listactivity ), so I explain as follows.
In my app I have two listactivities which uses two different listviews:
CODE:.......
As required by android, listview must have an ID which is exactly "@android:id/list". If I set the listview in both listview1 and listview2 with the same ID, then they will end up using the same format of listview, which is not what I want. But if I set one of the IDs to be sth like "@+id/listview2", android gave me the error: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
My listview is sort of complicated, customed list with image icons and text, so in my code, I also extended the ListAdapter:
CODE:........
View 1 Replies
View Related
Oct 2, 2010
I'm having a several issues with ListViews.
The first problem is the layout that I use for every row of the listview. When I click in a row I've programmed that it expands with some other views. All works fine, but when I try to click again for shrink it, it seems that it's no focusable and doesn't highlight and, of course, it doesn't shrink. If I change the deprecated singleLine in the XML to inputType="text" all works fine but the row never highlithts.
The second problem goes when I try the method that Romain Guy said about the RelativeLayouts and the alignwithParentIfMissing. No matter whatever I try, but it seems impossible to implement in a ListView.
Another problem is with ellipsize, but it looks is a Android SDK bug and only works fine if I set singleLine in the attributes of the TextView
Well, I hope someone can helps me. I put the code of the listview and the XML of the layout. If you need some more code or information, as if you find any improvement or error.
CODE:..............
About the response of adamp, I've done this:
CODE:.......................
And finally, I have this listener:
CODE:..........
Once I've done that, there is no change about the behaviour of the listview. But I noticed that only I can expand the row clicking in the textview, if I click inside the row but in a empty area nothing happens.
View 1 Replies
View Related
Aug 26, 2009
This application I've been working on has databases with multiple megabytes of data to sift through. A lot of the activities are just ListViews descending through various levels of data within the databases until we reach "documents", which is just HTML to be pulled from the DB(s) and displayed on the phone. The issue I am having is that some of these activities need to have the ability to search through the databases by capturing keystrokes and re-running the query with a "like %blah%" in it. This works reasonably quickly except when the user is first loading the data and when the user first enters a keystroke. I am using a ResourceCursorAdapter and I am generating the cursor in a background thread, but in order to do a listAdapter.changeCursor(), I have to use a Handler to post it to the main UI thread. This particular call is then freezing the UI thread just long enough to bring up the dreaded ANR dialog. I'm curious how I can offload this to a background thread totally so the user interface remains responsive and we don't have ANR dialogs popping up.
Just for full disclosure, I was originally returning an ArrayList of custom model objects and using an ArrayAdapter, but (understandably) the customer pointed out it was bad memory-manangement and I wasn't happy with the performance anyways. I'd really like to avoid a solution where I'm generating huge lists of objects and then doing a listAdapter.notifyDataSetChanged/Invalidated()
Here is the code in question:
CODE:.....................
View 2 Replies
View Related
Dec 16, 2009
I used two listviews like this if my problem is one back line is coming inbetween two listviews.But i dont want that that balck line in betweem them.
View 2 Replies
View Related
Jan 7, 2010
In my ListActivity, I need header and footer views (on the top and bottom of the list) to be used as previous page and next page buttons on my list, respectively, because I want to display only 20 items at a time.
I set my header and foot views by doing:
CODE:............
This works fine, but I need to dynamically remove and add these header and footer views, because some pages of my list may not have a next page button or a previous page button.
The problem is, I cannot call addHeaderView or addFooterView after I have called setListAdapter.
View 4 Replies
View Related
Nov 19, 2010
The Twitter application for Android has a nice way of refreshing the listview by pulling down and automatically refreshing the data source.
View 1 Replies
View Related
Mar 31, 2010
I want to know how to change dynamically a ListView's item layout. To be exact, i want to know the method that the ListView's bindView method is called at runtime. if the bindView method is artificially called by a other method. then i will change a ListView's item layout.
View 1 Replies
View Related
Mar 26, 2010
I have a listview with 200 items. I use a custom view for each row. There is a code that takes some time to calculate, and because of this the list hangs out on scrolling and loads in slow (2-3sec). I have subclassed SimpleCursorAdapter, and using Filterable and SectionIndexer. I have in mind to show initially the name of the record, and put in a thread the calculation, and will show up later when it's done. How do I push back some work, and later update the listview to include the calculated data? This should show up on fly without user interaction.
View 2 Replies
View Related
Aug 18, 2010
I have a ListView with different layouts for different items. Some items are separators. Some items are different because they hold different kinds of data, etc.
I want to implement ViewHolders to speed up the getView process, but I'm not quite sure how to go about it. Different layouts have different pieces of data (which makes naming difficult) and different numbers of Views I want to use.
How should I go about doing this?
The best idea I can come up with is to create a generic ViewHolder with X items where X is the number of Views in an item layout with the highest number of them. For the other views with a small number of Views, I'll just use a subsection of those variables in the ViewHolder. So say I have 2 layouts I use for 2 different items. One has 3 TextViews and the other has 1. I would create a ViewHolder with 3 TextView variables and only use 1 of them for my other item. My problem is that this can get really ugly looking and feels really hacky; especially when an item layout may have many Views of many different types.
Here is a very basic getView:
CODE:..........
Suppose I had different types of row layouts, I could have a ViewHolder for each type of row. But what type would I declare "holder" to be at the top? Or would I declare a holder for each type and then use the one for the type of row I'm on.
View 1 Replies
View Related