Using a ListView to create a settings screen in Android?

I'm developing my first Android application, and I'd like to create a settings screen.

I'd like the screen to have a similar look-and-feel as the native phone-settings screens and the native "create/edit alarm" screen. Thus with different kinds of (statically defined) items vertically stacked with a thin line between them.

How do I define such screen?

I understand I can use the ListView, but this seems to be primarily meant for serving dynamic data using a ListAdapter, where each item is served in the same format. It seems to be possible to create different items (that is, some with checkbox, some with two text-lines, some with an icon) by creating my own ListAdapter and overriding getView but this seems like overkill. Should I be using a ListView for this purpose?


Asked by: Edward869 | Posted: 24-01-2022






Answer 1

There's no need to manually create and format a ListView - there are ways in the API to create Preference screens.

The most obvious is PreferenceActivity.

You can define all your preferences in an XML file, a bit like a layout, and then load them with addPreferencesFromResource() or you can create a number of PreferenceScreen objects in code and populate them with Preference objects that way.

The best thing do would be to look at the API Demos application provided with the Android API. This contains lots of good examples of managing preferences. Here's how it creates preferences from code and here's a sample preferences XML file. There are other examples showing more advanced things like preference dependencies and preference listeners.

Answered by: Lucas529 | Posted: 25-02-2022



Answer 2

Actually in the built-in alarm application, for edit and create alarms, there are two activities, one for create and one for edit.

The Create Alarm activity is the first one with the digital clock. The Edit Alarm activity is started by clicking on a listed alarm from the Create Alarm activity.

Edit Alarm implements PreferenceActivity, but Create Alarm is more complex (custom cursor adapter to list the alarms).

Have a look at the sources:

Answered by: Kate215 | Posted: 25-02-2022



Similar questions

listview - Android - ICS Settings Adapter

Is there any kind of predefined adapter or custom utility that can help me quickly create a ListView of settings that feels like the native ICS one? I've read this document extensively: http://developer.android.com/design/patterns/settings.html#flow-structure And understand it perfectly, but it see...


ListView Headers same as Android settings

I would like to implement a section header like on my listview. The one that can be found on android's settings menu. Is there a native way of implementing this without using 3rd party resources? Thanks! Settings Menu on Android with Section Headers. Sample image.


ListView in android 5.0 settings screen

How do i implement the listView which is in the android 5.0 settings screen in my project.I searched a lot and found no reasonable answers.Any help is appreciated


android - How to pass more than one array to a listview?

I am using a ListView to display items. Currently I am passing a String array of items to it. But I want to pass one more array and display its items along with the items of the first array; that is, somehow having two lines of text. How can I do that?


Android ListView Selector Color

Hi All, I have 2 questions regarding a ListView in Android: How can I get the color of the listview's focused row ? I tried to use the ListView.getSelector() method, which according to its documentation should give me what I'm looking for, but it's giving me a Drawable object which I don't know how to retrieve the color from (if possible...).


android - Which is better loading of images for ListView?

I am wondering if which of the two is better in loading images in a listview from web, is it by batch through some number of threads that are running simultaneously or one by one through thread queue? I have noticed (but I don't know if that is really the implementation) from the youtube app that the images are loaded by batch and it is kinda fast. Even for not only loading images but also requesting some data from...


how to list the audio files in a Listview in android

I am new to this android application development. I have a audio files in a particular directory. I want to list the those audio files in a listView. please tell me how to do this activity.


android - Making child ListView scroll

Hello I am trying to make a terminal type app that is wider than the actual android screen. A listview is great except that I don't want the text to wrap. If the text is wider than the screen I want it to print the full text and then the user can scroll over horizontally if they want to see what was printed off the screen. Just FYI this is for ascii type tables. I have followed this example:


listview - How to popup list like a spinner without spinner in android?

I have a spinner widget in my activity which lets users pick a list name. Normally, the function of the spinner is to switch between lists but for a couple of instances, I swap out the selection change listener to perform a different function with the same list of options. Once the selection has been made, the old listener is restored and life goes on. This is a bad and buggy arrangement. Instead, I would...


android - display item of listview

I have a list view having several items and it is multichoice list. I want to display the checked item of list view. how i can do this.can anyone help me???


android - Specify view to use when ListView is empty?

I can't find this in the docs - isn't there a way to specify a View to use for a ListView if the adapter is empty? Thanks


listview - Round bottom corners on Android Bitmap?

Hey all, what would be best practice for clipping the bottom borders of a Bitmap? Just manipulate the Bitmap itself or overlay an alpha mask drawable or ...? The whole story: I've a Listview which looks like the iPhone's grouped UITableView style. I would like to display a Bitmap in the last row, but for now the Bitmap overlaps my custom background drawable of the Listview cell. Thx in adva...


java - How do I fill a ListView (in Android) with XML or JSON data?

I read a tutorial, and it uses SQLlite and "SimpleCursorAdapter" to fill the list with items. This is the code the tutorial taught me. private void fillData() { // Get all of the notes from the database and create the item list Cursor c = mDbHelper.fetchAllNotes(); startManagingCursor(c); String[] from = new String[] { NotesDbAdapter.KEY_TITLE }; int[] to = new int[]...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top