Bonjour à tous, voilà je vous expose mon problème.

J'aimerais remplir une listview avec des ToggleButton, mais j'aimerais que mes ToggleButton soient présents seulement dans les dernières lignes de ma listview.

Voici mon code test trouvé sur internet:
Ma listView:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <ListView
        android:id="@+id/lv_countries"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        tools:context=".MainActivity" />
 
</RelativeLayout>
Mes items:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <TextView
        android:id="@+id/tv_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:paddingLeft="5dp" />
 
        <ToggleButton
            android:id="@+id/tgl_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:focusable="false"
            android:clickable="false" />
</RelativeLayout>
Et mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
String[] countries = new String[] {
    	     "India",
    	        "Pakistan",
    	        "Sri Lanka",
    	        "China",
    	        "Bangladesh",
    	        "Nepal",
    	        "Afghanistan",
    	        "North Korea",
    	        "South Korea",
    	        "Japan"
    };
 
    public boolean[] status = {
    			true,
    	        false,
    	        false,
    	        false,
    	        false,
    	        false,
    	        false,
    	        false,
    	        false,
    	        false
    };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
 
		ToggleButton tgl=(ToggleButton) findViewById(R.id.tgl_status);
 
		  if(savedInstanceState!=null){
	            status = savedInstanceState.getBooleanArray("status");
	        }
 
	        ListView lvCountries = (ListView) findViewById(R.id.lv_countries);
	        List<HashMap<String,Object>> aList = new ArrayList<HashMap<String,Object>>();
 
	        for(int i=0;i<10;i++){
	            HashMap<String, Object> hm = new HashMap<String,Object>();
	            hm.put("txt", countries[i]);
	           	           hm.put("stat",status[i]);
	            aList.add(hm);
	        }      
	        String[] from = {"txt","stat" };  
	        int[] to = { R.id.tv_item, R.id.tgl_status};
	        SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.lv_layout, from, to);
	        lvCountries.setAdapter(adapter);
	}
Disont que j'aimerais que les deux dernières lignes de ma listview comporte un ToggleButton.

Comment puis-je faire cela?

J'ai bien essayé de modifier le code pour ne pas ajouter de toggleButton mais rien n'y fait il apparait dans toutes mes lignes :/.

Merci d'avance