Android ListView - android

I have two activities, both of which use a listview. I called one "android:list", but called the second one "#+id/myList". Now, my application crashes on startup with a "must have android:list" error message. How does one get around this?

If your Activity's extend ListActivity, then your ListViews must have an ID of android:list. If they are two separate Activity's then it is OK for both to have a ListView with the same ID - the important thing is not to have two Views with the same ID in the same Layout.

ListActivity looks for a ListView with the ID android.R.id.list to get a reference so it can provide all the API features for the developer. Without that it thinks there's no list and crashes when trying to use it. Just define the list in xml like you do with the other one and it will start working. All the pieces need to fit together like a jigsaw puzzle.

I think your activity must be extended from ListActivity, so you should create a listview with the tag android:name="android:id/list" in the layout xml. Hopes useful to you!

Related

What is the difference in ListViews and other Views when using findViewById?

When finding most views in Android, one can usually use findViewById(R.id.my_id) where the id looks like android:id="#+id/my_id" in the XML file.
When using any kind of ListView, we have to use findViewById(android.R.id.my_id) and in the XML we use android:id="#android:id/my_id".
Can someone please explain to me why this is and why it makes a difference?
Thanks!
When using any kind of ListView, we have to use findViewById(android.R.id.my_id) and in the XML we use android:id="#android:id/my_id".
No, you do not. In fact, what you have there most likely will not compile.
If you are inheriting from classes like ListActivity or ListFragment, then you need to use a framework-defined #android:id/list / android.R.id.list identifier for the ListView that those classes will manage. That is so ListActivity or ListFragment can find the ListView that you want it to manage for you.
In any other circumstance, you are welcome to name your ListView whatever you like, as with any other widget or container.
In your custom views you usually define you own ids #+id/your_own_id. Elements from libraries use the same notation. However elements from the SDK use the android prefix.
If you include a ListView in your layout it is common to give it a standard id #android:id/list. Some SDK classes expect standard ids. For example if you had a custom layout for a ListFragment the layout HAS TO include a ListView element with a standard id.

How to create Activity dynamically

I have some idea for my app. But I don't know how to do.
Basic, we create activity then load it, or call some another Activity from buttom...
My idea is:
We have a ListView, can add, remove item. So everytime we add a item, we add a Activity,too.
How many items in listview so activity is many,too.
Ho to do that?
Sorry you can not create Activity dynamically but you can assign already exist activity to number of items in listview.
You can also make your activity to behave differently according to different values but all is depends on your requirement and your logical implementation.
Make sure that all your Activity is listed in Manifest. Do remember.
Check this & this links mentioning the same.

Is it possible to have multiple list activities in one application in android?

I'm wondering, because I have occasion to use two different activities that both use listviews and obviously I can just make one a normal activity with a listview, but I checked the api, and there was no mention of this....
I tried using two listActivities just normally but, it seems there is a conflict because both listviews in each activity have to be named list, so there is still only one "list" id in the R file...
anyone know if its possible to use two?
The ListView object's ID should be indeed list, but you can have several layout files (with arbitrary names) with such an object inside. So yes, you can have as many ListActivities in the project as you wish. Derive your own classes from ListActivity, and use setContentView() to feed the right layout file to it.

How to handle ListView in this situation Android?

I ran into the situation that I need a way to edit the data of list-view item from another activity. I can handle the click event on each item, then edit it on the fly. However, I still prefer to handle all the editing in a separate activity. My listview item is customized from BaseAdapter.
Here is my main page,
Each item within the ListView, contains two other TextView. When the I hit the menu setting, it will go to another activity where I can edit and update the information:
I'm currently having two solutions in mind. Either retrieving data from the previous activity and update the whole ListView (which I think it's kinda expensive in the case user just edit one item). Or I can just get rid of the ListView and create a bunch TextView in the xml, by doing this I can just reference to each TextView by their id. So my question is, which way is preferred in this case? Any suggestion would be greatly appreciated.
Your ListView is displaying Email, Name, Headline, etc? That should be a fixed XML layout with TextView entries, I think. ListView is for variable numbers of elements. You CAN implement it with a ListView, but I wouldn't.
However, your concern about updating the whole list being overkill, I wouldn't worry about that either. You're talking about 7-10 fields. The amount of time Android needs to run through its lifecycle and display everything will dwarf you updating a few fields.
You can use SharedPreferences for this. You can create a wrapper class through which you can access the preferences.Thats the usual way to go about solving these kind of problems. You can check this for details.
You can have it as a variable in your application class, so that you can access that in a global context.
Use text views instead. List View code has been optimized for large amounts of data only and not recommended for small data.

Android List problem

I've create an application using JSON. It shows the list of some items from one link whatever i used in Codes. In my application i've using 2 layouts for display the items. First layout doesn't have any problem. But, when i go to next layout the result of first layout also show here and overrides the second layout's contents. I'm using android:list for list that. Can anyone clarify this doubt? Thanks in Advance.
Make sure your ID on your Lists are different. This could cause the problem.

Categories

Resources