I have a list view of schedules where it says the name of the line, the stop, the time and state.
If someone can explain to me how the android organization works thanks, I just need to know how to organize it in ascending and ascending order, for example the line name field.
The goal is for example what I saw in the English stackoverflow:
Unsorted:
Record Color Clothes
0 blue shoes
1 yellow pants
2 red boots
3 black coat
Sorted by Color:
Record Color Clothes
3 black coat
0 blue shoes
2 red boots
1 yellow pants
Sorted by Clothes:
Record Color Clothes
2 red boots
3 black coat
1 yellow pants
0 blue shoes
So for a listview with the "ArrayList" only with the two ascending and descending order. The English post:
My code from my list:
try {
jsonArray = new JSONArray(myJSON);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject cursor = jsonArray.getJSONObject(i);
String title = cursor.getString(TAG_TITLE);
horarioHora.add(cursor.getString(TAG_TITLE));
String estado = cursor.getString(TAG_DATESTART);
horarioLinha.add(cursor.getString("linhaNome"));
horarioParagem.add(cursor.getString("paragemRua"));
HashMap<String, String> horario = new HashMap<>();
horario.put(TAG_TITLE, title);
horario.put(TAG_DATESTART, estado);
horarioList.add(horario);
}
ListAdapter adapter = new SimpleAdapter(this, horarioList, R.layout.list_item,
new String[]{TAG_TITLE, TAG_DATESTART},
new int[]{R.id.title, R.id.estado});
listaHorarios.setAdapter(adapter);
dialog.dismiss();
Url = "http://dagobah.grifin.pt/tiagocoelho/utilizadorAndroid.php";
funcao = "utilizador";
get_data();
listaHorarios.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
HorariosActivity.this);
alertDialogBuilder
.setMessage("Quer adicionar o horário aos favoritos?")
.setCancelable(false)
.setPositiveButton("Adicionar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
try {
horarioitem = jsonArray.getJSONObject(position).toString();
Sthoras = horarioHora.get(position);
Stlinhas = horarioLinha.get(position);
Stparagens = horarioParagem.get(position);
tvlinhas.setText(Sthoras);
} catch (JSONException e) {
e.printStackTrace();
}
Url = "http://dagobah.grifin.pt/tiagocoelho/confirmaAddFavAndroid.php?Sthoras="+Sthoras+"&Stlinhas="+Stlinhas+"&Stparagens="+Stparagens+"&utilizadorId="+UtilizadorId2;
Url=Url.replace(" ", "%20");
funcao = "verificar";
get_data();
}
});
alertDialogBuilder.setNegativeButton("Cancelar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
}); //end setOnItemClickListener
} catch (JSONException e) {
e.printStackTrace();
}
}
I hope you can help me because really from what I already researched I can not understand the android organization.
For my program the organization can not be done via php or sql needs to be done by Android.