5
Several current Androids systems have menus like the one in the example below:
Notice that anywhere I touch my finger in the blue area under "Access my location" it turns on or off the switch and enables or disables the block in "Location Sources", and also makes the blue effect on the clicked block.
Without knowing very well the options that Android offers me I tried to do something similar, either would be the basis of what I really intend to do. I made the following code:
Activity.xml
<ListView
android:id="@+id/lstSegundaTela"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
Minhaactivity.java
lstSegundaTela = (ListView) findViewById(R.id.lstSegundaTela);
List<Map<String, String>> dados = new ArrayList<>();
String[] valores = new String[] {
"Acesso a minha localização",
"Satélite de GPS",
"Local de rede móvel e Wi-Fi"};
String[] descricoes = new String[] {
"Permitir que os aplicativos que solicitaram sua permissão " +
"usem seus dados de localização",
"Permitir que os aplicativos usem o GPS do telefone para " +
"determinar sua posição",
"Permitir que os aplicativos usem o serviço de localização " +
"do Google para determinar seu local mais rapidamente. Dados " +
"de localização anônimos serão coletados e enviados ao Google"};
for(int i=0; i<valores.length; i++) {
Map<String, String> linha = new HashMap<>();
dados.add(linha);
linha.put("Titulo", valores[i]);
linha.put("Subtitulo", descricoes[i]);
}
SimpleAdapter adapter = new SimpleAdapter(
this,
dados,
android.R.layout.simple_list_item_2,
new String[] {"Titulo", "Subtitulo"},
new int[] {android.R.id.text1, android.R.id.text2});
lstSegundaTela.setAdapter(adapter);
The result was as follows:
My doubts are:
How to place Switch and Checkbox components in the Listview line as an example above?
How was the "Location Sources" block created? Or it would be another Listview with a title?
You can check here: http://www.vogella.com/tutorials/AndroidListView/article.html
– Reiksiel
It was there that I saw to get as far as I got, after that I stopped. There is an example with Checkbox in Listview, but not according to the example I showed above.
– Math
This is simple, just create an item in xml with a
TextView
and aCheckbox
, and then use this item inListView
.– Jorge B.
@Math, these components are called Preferences (a look at http://developer.android.com/guide/topics/ui/settings.html), the titles are headers of Preferencecategory. If that’s not what you want to see in this tutorial by Cyril Mottier: http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
– Wakim
@Jorgeb. You mean I’d set up a template to use for each line? Hence I could for example make two Textview (one with large font and one with small font) and put together a component. There is no more something ready to do that?
– Math
@Wakim will look yes. Thank you.
– Math
Look at my answer. If you want another Textview for the title just add also in XML.
– Jorge B.