2
I am following a tutorial on the Internet and I came up with a small doubt that is the following. In the tutorial, I place items from a String array in a listview and in it I can select various options by the simple_list_item_checked.
I’m managing to show which are selected and which are not selected, what I needed is to play all selected to another screen, the problem is how to play as String[], because in the example it is only as a String
What I need then is to play all states to the tela2 as the String type[]
Can I get some help? Lease?
listaEstados = new String[]{"São Paulo", "Rio de Janeiro", "Minas Gerais", "Rio Grande do Sul", "Santa Catarina", "Paraná"};
public void onClickMarcados(View view){
String listaEstadosSelec = "";
//Cria um array com os itens selecionados no listview
SparseBooleanArray selecionados = lv.getCheckedItemPositions();
for (int i=0; i<selecionados.size(); i++){
//Pega os itens marcados
listaEstadosSelec = listaEstadosSelec + listaEstados[selecionados.keyAt(i)]+", ";
}
Intent intent = new Intent(MainActivity.this, Tela2_Activity.class);
intent.putExtra("itens", listaEstadosSelec);
startActivity(intent);
//Toast.makeText(getBaseContext(), "Estados marcados: "+listaEstadosSelec, Toast.LENGTH_LONG).show();
}
It did not work very well, no friend, from the following error: The method putStringArrayListExtra(String, Arraylist<String>) in the type Intent is not applicable for the Arguments (String, List<String>)
– Emerson Moraes
Ah tah, pardon , I will correct in response
– Cícero Moura
It is because the Arrays.asList method returns a List and not an Arraylist. Then, just make a new instance of Arraylist by placing the type (important in this case) and passing the List back to the constructor.
– Cícero Moura
Roger that, it worked out, buddy. Thanks for your help!
– Emerson Moraes