[Android] organisé une listview par Catégorie

slama007 Messages postés 8 Date d'inscription mardi 28 avril 2009 Statut Membre Dernière intervention 9 août 2012 - 31 juil. 2012 à 03:38
Bonjour Tout le monde :)


Voila j'ai une ListView composé par des données ( regarder l'image )



je veux trouvé une solution pour que j'affiche les donnée suivant L'IMEI ( colleur en Vert dans la photo ) par ordre croissant ou décroissent...


Probléme: Afficher les donnée par catégorie ( par exemple dans mon cas il affiche IMEI1 IMEI2 IMEI3 .... et quand je clic sur l'un d'eux il m'affiche tout les info sur les IMEI qui porte le méme numéro )


voici le code PHP :

<?php

 $base =  mysql_connect ('localhost', 'root', '');  
 mysql_select_db ('trackeur', $base) ;  
$p=0;
$req mysql_query("select * from clients WHERE username 'roger'");
while($dnn = mysql_fetch_array($req))
{
$v="A";
$IMEI = $dnn['IMEI'];

$req1 mysql_query("select * from data WHERE IMEI '$IMEI' ORDER BY id DESC");
while($row1 = mysql_fetch_array($req1))

{   
     $output1[]=$row1;    
  }
 
  }
 //on encode en JSON 
 
echo("{"general":");
 print(json_encode($output1));
 echo("}");

 mysql_free_result ($req1);  
 $lat = $row1['Latitude']/100;
$lng = $row1['Longitude']/100;
$url = "http://maps.google.com/maps/geo?q=$lat,$lng&amp;output=json&amp;sensor=false";
$data = @file_get_contents($url);          //read the HTTP request
$jsondata = json_decode($data,true);       //parse the JSOPN response

?>




et voila le Code Java

package com.diablo;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class InfoMapG extends ListActivity {

// url to make request
private static String url  = "http://10.0.2.2/member.php";

// JSON Node names
private static final String TAG_Contact = "general";
private static final String TAG_IMEI = "IMEI";
private static final String TAG_id = "id";
private static final String TAG_Date = "Date";
private static final String TAG_Latitude = "Latitude";
private static final String TAG_Heure = "Heure";
private static final String TAG_Statut = "Statut";
private static final String TAG_Battery = "Battery";
private static final String TAG_Longitude = "Longitude";

// contacts JSONArray
JSONArray contacts = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.infomapgenral);

// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

// Creating JSON Parser instance
JSONParser jParser = new JSONParser();

// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);

try {
// Getting Array of Contacts
contacts = json.getJSONArray(TAG_Contact);

// looping through All Contacts
for(int i = 0; i < contacts.length(); i++){
JSONObject c = contacts.getJSONObject(i);

// Storing each json item in variable
String id = c.getString(TAG_id);
String IMEI = c.getString(TAG_IMEI);
String Date = c.getString(TAG_Date);
String Latitude = c.getString(TAG_Latitude);
String Heure = c.getString(TAG_Heure);
String Longitude = c.getString(TAG_Longitude);


// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();

// adding each child node to HashMap key => value
map.put(TAG_id, id);
map.put(TAG_IMEI, IMEI);
map.put(TAG_Date, Date);
map.put(TAG_Longitude, Longitude);
map.put(TAG_Latitude, Latitude);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}


/**
 * Updating parsed JSON data into ListView
 * */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { TAG_IMEI, TAG_Date, TAG_Latitude, TAG_Longitude },new int[] {
R.id.IMEI, R.id.date, R.id.latitude, R.id.longitude });

setListAdapter(adapter);

// selecting single ListView item
ListView lv = getListView();

// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {


public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// getting values from selected ListItem
String imei = ((TextView) view.findViewById(R.id.IMEI)).getText().toString();
String date = ((TextView) view.findViewById(R.id.date)).getText().toString();
String latitude = ((TextView) view.findViewById(R.id.latitude)).getText().toString();
String longitude = ((TextView) view.findViewById(R.id.longitude)).getText().toString();

// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItem.class);
in.putExtra(TAG_IMEI, imei);
in.putExtra(TAG_Date, date);
in.putExtra(TAG_Latitude, latitude);
in.putExtra(TAG_Longitude, longitude);
startActivity(in);

}
});



}

}




sa serai gentille si quelqu'un peu m'aidai pour modifier mon code et obtenir ce que je veux ou me donnée un exemple sur un truc qui ressemble a sa
et Merci d'avance
Rejoignez-nous