Aller au contenu

récupérer un arrayList d'HashMap et renseigner dans un tableau


Recommended Posts

Bonjour,
Voilà deux mois que je bosse sur un projet audio sous Linux.
J'essaye d'éxtraire ma listView pour la renseignée dans mon tableau (TableLayout) mais je ne sais pas par où commencer.

package com.example.audiolinux;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
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;
import android.widget.TableLayout;
 
public class MainActivity extends Activity {
 
	private ListView lvListe;
	private TableLayout tab;
	
    /** Called when the activity is first created. */
    @[member=override]
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //Récupération de la listview créée dans le fichier activity_main.xml
        lvListe = (ListView)findViewById(R.id.lvListe);
        tab  = (TableLayout) findViewById(R.id.tab);
        
        //Création de la ArrayList qui nous permettra de remplire la listView
        final ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
 
        //On déclare la HashMap qui contiendra les informations pour un item
        HashMap<String, String> map;
        
        //Création d'une HashMap pour insérer les informations du premier item de notre listView
        map = new HashMap<String, String>();
        //on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
        map.put("titre", "France");
        //on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml
        map.put("description", "Pays 1");
        //on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        //enfin on ajoute cette hashMap dans la arrayList
        listItem.add(map);
 
      //On refait la manip plusieurs fois avec des données différentes pour former les items de notre ListView
        
        map = new HashMap<String, String>();
        map.put("titre", "Allemagne");
        map.put("description", "Pays 2");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Russie");
        map.put("description", "Pays 3");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
        
        map = new HashMap<String, String>();
        map.put("titre", "Quebec");
        map.put("description", "Pays 4");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Turquie");
        map.put("description", "Pays 5");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Maroc");
        map.put("description", "Pays 6");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
        
        map = new HashMap<String, String>();
        map.put("titre", "Australie");
        map.put("description", "Pays 7");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Vénézuela");
        map.put("description", "Pays 8");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Algérie");
        map.put("description", "Pays 9");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
        
        map = new HashMap<String, String>();
        map.put("titre", "Cameroun");
        map.put("description", "Pays 10");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Tunisie");
        map.put("description", "Pays 11");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Sénégal");
        map.put("description", "Pays 12");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
        
        map = new HashMap<String, String>();
        map.put("titre", "Japon");
        map.put("description", "Pays 13");
        map.put("img", String.valueOf(R.drawable.bouton_genre));
        listItem.add(map);
        
        
        
        //Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
        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});
        //On attribut à notre listView l'adapter que l'on vient de créer
        lvListe.setAdapter(mSchedule);
        //Enfin on met un écouteur d'évènement sur notre listView
        lvListe.setOnItemClickListener(new OnItemClickListener() {
			@[member=override]
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) {

				
				
        	}
         });
    }
}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    tools:context=".MainActivity" >
    
    <RelativeLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="550dp"
        android:layout_height="30dp"
        android:contentDescription="@+id/imageView1"
        android:src="@drawable/banner_edit" />

    <ListView
        android:id="@+id/lvListe"
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#b0b0b0"
        android:maxLines="1"
        android:padding="5dp" />

    </RelativeLayout>
    <ScrollView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
    <TableLayout
        android:id="@+id/tab"
        android:layout_width="600dp"
        android:layout_height="335dp"
        android:background="#ffffff" >

        <TableRow
            android:id="@+id/TableRow01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#cac9c9"
            android:paddingBottom="1dp" >

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="200dp"
            	android:layout_height="200dp"
				android:layout_marginLeft="10dp"
				android:layout_marginTop="10dp"
                android:background="#cac9c9"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/battlefield_3" 
                android:contentDescription="@+id/imageButton1"/>

            <TextView
                android:id="@+id/TextView19"
                android:padding="100dip"
                android:textColor="#000000" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="1dp" >

            <TextView
                android:id="@+id/artiste"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="@string/artiste"
                android:layout_weight="1"
                android:background="#b0b0b0"
                android:orientation="vertical"
                android:padding="18dip"
                android:textColor="#000000"/>

            <EditText
                android:id="@+id/valArtiste"
                android:ems="5"
                android:inputType="textPersonName" 
                android:layout_weight="2"
                android:background="#a09f9f"
                android:padding="18dip"
                android:textColor="#000000"/>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="1dp" >

            <TextView
                android:id="@+id/album"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="@string/album"
                android:layout_weight="1"
                android:background="#b0b0b0"
                android:orientation="vertical"
                android:padding="18dip"
                android:textColor="#000000" />

            <EditText
                android:id="@+id/editText2"
                android:ems="5"
                android:inputType="textPersonName" 
                android:layout_weight="2"
                android:background="#a09f9f"
                android:padding="18dip"
                android:textColor="#000000"/>
        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="1dp" >

            <TextView
                android:id="@+id/date"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="@string/date"
                android:layout_weight="1"
                android:background="#b0b0b0"
                android:orientation="vertical"
                android:padding="18dip"
                android:textColor="#000000" />


            <EditText
                android:id="@+id/editText3"
                android:ems="5"
                android:inputType="date" 
                android:layout_weight="2"
                android:background="#a09f9f"
                android:padding="18dip"
                android:textColor="#000000"/>
        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="1dp" >

            <TextView
                android:id="@+id/genre"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="@string/genre"
                android:layout_weight="1"
                android:background="#b0b0b0"
                android:padding="18dip"
                android:textColor="#000000" />

            <EditText
                android:id="@+id/editText4"
                android:ems="5"
                android:inputType="textPersonName" 
                android:layout_weight="2"
                android:background="#a09f9f"
                android:padding="18dip"
                android:textColor="#000000"/>
        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="1dp" >

            <TextView
                android:id="@+id/compositeur"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="@string/compositeur"
                android:layout_weight="1"
                android:background="#b0b0b0"
                android:padding="18dip"
                android:textColor="#000000" />

            <EditText
                android:id="@+id/editText5"
                android:ems="5"
                android:inputType="textPersonName" 
                android:layout_weight="2"
                android:background="#a09f9f"
                android:padding="18dip"
                android:textColor="#000000"/>
        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="1dp" >

            <TextView
                android:id="@+id/organisation"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="@string/organisation"
                android:layout_weight="1"
                android:background="#b0b0b0"
                android:padding="18dip"
                android:textColor="#000000" />

            <EditText
                android:id="@+id/editText6"
                android:ems="5"
                android:inputType="textPersonName" 
                android:layout_weight="2"
                android:background="#a09f9f"
                android:padding="18dip"
                android:textColor="#000000"/>
        </TableRow>
    </TableLayout>
</ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
 
    <ImageView
		android:id="@+id/img"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
	   	android:layout_gravity="center_vertical"
	   	android:contentDescription="@+id/img"
	   	android:padding="10dp"/>
 
	<LinearLayout 
	    android:orientation="vertical"
	    android:layout_width="0dp"
	    android:layout_height="wrap_content"
	   	android:layout_gravity="center_vertical"
	   	android:paddingLeft="10dp"
	    android:layout_weight="1">
 
	    <TextView android:id="@+id/titre"
	         android:layout_width="fill_parent"
	         android:layout_height="fill_parent"
	         android:textSize="16sp"
	         android:textStyle="bold"
	         />
 
	    <TextView android:id="@+id/description"
	         android:layout_width="fill_parent"
	         android:layout_height="fill_parent"
	         />
 
    </LinearLayout>
</LinearLayout>

Merci d'avance

Lien vers le commentaire
Partager sur d’autres sites

Bonjour,

Les questions techniques concernant le développement d'applis doivent être posées dans une des sections consacrées au développement ici : https://forum.frandroid.com/forum/7-d%C3%A9veloppement/

Cette section est réservée à la présentation d'applis publiées.

Je déplace pour cette fois-ci, merci d'y faire attention la prochaine fois :)

Lien vers le commentaire
Partager sur d’autres sites

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

×   Collé en tant que texte enrichi.   Coller en tant que texte brut à la place

  Seulement 75 émoticônes maximum sont autorisées.

×   Votre lien a été automatiquement intégré.   Afficher plutôt comme un lien

×   Votre contenu précédent a été rétabli.   Vider l’éditeur

×   Vous ne pouvez pas directement coller des images. Envoyez-les depuis votre ordinateur ou insérez-les depuis une URL.

×
×
  • Créer...