質問

I'm learning android programming, and here is my doubt: I can create a full screen ListView with the ListView object itself, or through a ListActivity.

Is there one that is preferable to the other, whether it be for efficiency reasons, code maintainability, or Android best-practices?

役に立ちましたか?

解決

If it's fullscreen, it should probably be a ListActivity.

It's not always clear how to divide parts of an app into Activities, but one Activity per screen is pretty common.1 You likely shouldn't be showing a fullscreen ListView over other Views in a single Activity.

Note that ListActivity is just a convenience to save a bit of boilerplate code for a common Activity layout. The layout and IDs are preset, so that you don't have to create them. However, if you were designing an app that included a fullscreen list, but custom Activities (maybe everything subclasses a BaseActivity class that handles checking authorization), there's no harm in making your own Activity with a fullscreen ListView as its layout. (In that case, I'd recommend looking at the features of ListActivity like the empty view as it's more complex than merely a single ListView.)

1. This is actually more complex nowadays because Fragments are the norm and have even fuzzier boundaries, but we'll leave them out of this discussion.

他のヒント

No, there isn't.

It depend on that activity function.

To display simple data or to use a listview as a picker then ListActivity is not a bad choice.

But, for more complex functions. rather than those you are forced to use listview inside an activity that contain other controls too.

in my opinion making a listView in xml is better.

in my application i have a listView and a tixtview in a framelayout , loading the listview data from database , if the database is empty i hide the listview and show the textView ( telling the user there is no data to show ) , and if there is data in the database i show the listview and hide the textview

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top