Bonjour à tous,

J'ai une fonction addItem que j'utilise pour ajouter un nom de joueur par défaut dans un EditText. Une fois les noms éditer par l'utilisateur j'aimerais les récupérer. J'avais penser utiliser : View joueur = mContainerView.getChildAt(num). Mais j'obtiens un View. Comment puis-je faire pour récupérer les noms des joueurs sous forme de string afin de les utiliser par la suite?
Voici mon code (fonction addItem et mes deux fichiers xml ):


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
private void addItem() {
        // Instantiate a new "row" view.
       final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(
                        R.layout.list_item_example, mContainerView, false);
 
        // Set the text in the new row from PLAYER[].
 
        ((TextView) newView.findViewById(android.R.id.text1)).setText(PLAYER[i]);
 
        // Set a click listener for the "X" button in the row that will remove the row.
        newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Remove the row from its parent (the container view).
                // Because mContainerView has android:animateLayoutChanges set to true,
                // this removal is automatically animated.
                mContainerView.removeView(newView);
 
                // If there are no rows remaining, show the empty view.
                if (mContainerView.getChildCount() == 0) {
 
                    findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
                }
            }
 
        });
        // Because mContainerView has android:animateLayoutChanges set to true,
        // adding this view is automatically animated.
        mContainerView.addView(newView, 0);
       }
    }


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
private static final String[] PLAYER = new String[]{
            "Player 1", "Player 2", "Player 3", "Player 4", "Player 5",
            "Player 6", "Player 7", "Player 8"
    };
*

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
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:listPreferredItemHeightSmall" 
    android:orientation="horizontal"
    android:showDividers="middle"
    android:divider="?android:dividerVertical"
    android:dividerPadding="8dp"
    android:gravity="center">
 
    <!-- Dummy text view that will display the name of a random country. -->
    <EditText android:id="@android:id/text1"
        style="?android:textAppearanceMedium"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:paddingLeft="?android:listPreferredItemPaddingLeft" 
        />
 
    <!-- A button that, when pressed, will delete this list item row from its container. -->
    <ImageButton android:id="@+id/delete_button"
        android:layout_width="48dp"
        android:layout_height="match_parent"
        android:src="@drawable/ic_list_remove"
        android:background="?android:selectableItemBackground"
        android:contentDescription="@string/action_remove_item" />
 
</LinearLayout>
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <!-- A vertical LinearLayout in a ScrollView. This emulates a ListView (and is lighter weight
         than a ListView when there aren't many rows). -->
    <ScrollView android:layout_width="match_parent"
        android:layout_height="match_parent">
 
        <!-- Note that this LinearLayout has the "animateLayoutChanges" property set to true.
             This tells the framework to automatically animate child views (in this case, rows)
             as they are added to and removed from the LinearLayout. -->
        <LinearLayout android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:showDividers="middle"
            android:divider="?android:dividerHorizontal"
            android:animateLayoutChanges="true"
            android:paddingLeft="16dp"
            android:paddingRight="16dp" >
 
 
 
        </LinearLayout>
 
    </ScrollView>
 
    <!-- The "empty" view to show when there are no items in the "list" view defined above. -->
 
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >
 
 
 
 
    <Button
        android:id="@+id/apply"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="29dp"
        android:enabled="false"
        android:text="@string/apply" />
 
    <TextView
        android:id="@android:id/empty"
        style="?android:textAppearanceSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="125dp"
        android:padding="32dp"
        android:text="@string/empty_player"
        android:textColor="?android:textColorSecondary" />
 
</RelativeLayout>
</FrameLayout>