how to create a sublist?

Put your problem here if it does not fit any of the other categories.

how to create a sublist?

Postby jaafar » Thu Mar 31, 2011 10:19 pm

I create a list but I don't know how to create a sublist it mean when the user taps on such account there is another list
here is my list
Code: Select all
package com.tutomobile.android.listView;

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

import com.tutomobile.android.listView.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;


import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class Tutoriel5_Android extends Activity {

   private ListView maListViewPerso;
   

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.liste);

       
        maListViewPerso = (ListView) findViewById(R.id.listviewperso);
       
       
        ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();

       
        HashMap<String, String> map;

       
        map = new HashMap<String, String>();
       
        map.put("titre", "compte");
        map.put("description", "information sur compte  ");
       
       
        listItem.add(map);

       

        map = new HashMap<String, String>();
        map.put("titre", "opération");
        map.put("description", "les opérations ");
       
        listItem.add(map);

        map = new HashMap<String, String>();
        map.put("titre", "suvui ");
        map.put("description", "suvui de compte ");
     
        listItem.add(map);

       

       
        SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.affichageitem,
               new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});

       
        maListViewPerso.setAdapter(mSchedule);

   
        maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
         @Override
           @SuppressWarnings("unchecked")
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            
              HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
              
              AlertDialog.Builder adb = new AlertDialog.Builder(Tutoriel5_Android.this);
              
              adb.setTitle("Sélection Item");
              
              adb.setMessage("Votre choix : "+map.get("titre"));
              
              adb.setPositiveButton("Ok", null);
              
              adb.show();
           }
         });

    }
}
jaafar
Freshman
Freshman
 
Posts: 7
Joined: Sat Mar 12, 2011 2:45 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 10 guests