bonjour :)
j'essaye de faire une listview avec des colonnes et un bouton qui doit ajouter une ligne mais le problème que les colonnes ne sont pas ordonnées comme si elles n'existent pas
merci
Version imprimable
bonjour :)
j'essaye de faire une listview avec des colonnes et un bouton qui doit ajouter une ligne mais le problème que les colonnes ne sont pas ordonnées comme si elles n'existent pas
merci
Salut,
Peux tu être un peu plus bavarde stp ;)?
Comment crées tu ta listView?
Merci,
Christian
Bonjour , comment ça va :)
Alors pour encore clarifier les chose , je veux récupérer des données (onActivtyResult) d'une activity qui est déclenchée (startActivityForResult) lors de l'appui sur un imagebutton "AddBtn" dans la class ci-dessous dans une intent , les extraire et puis les ajouter dans une ligne dans la listview
j'ai essayée avec un bout de code que je l'ai écrit mais ça na pas marcher j'ai eu l'erreur si dessous :
la class java :Code:
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 08-06 09:06:20.364 25129-25129/com.example.... E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=5478, result=-1, data=Intent { (has extras) }} to activity {com.example.filali.clerk_project/com.example.filali.clerk_project.SchedaLavoro}: java.lang.IllegalArgumentException: columnNames.length = 4, columnValues.length = 3 at android.app.ActivityThread.deliverResults(ActivityThread.java:3539) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3582) at android.app.ActivityThread.access$1300(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: java.lang.IllegalArgumentException: columnNames.length = 4, columnValues.length = 3 at android.database.MatrixCursor.addRow(MatrixCursor.java:103) at com.example.filali.clerk_project.List_Of_Articles.onActivityResult(List_Of_Articles.java:113) at com.example.filali.clerk_project.SchedaLavoro.onActivityResult(SchedaLavoro.java:88) at android.app.Activity.dispatchActivityResult(Activity.java:6139) at android.app.ActivityThread.deliverResults(ActivityThread.java:3535) ************at android.app.ActivityThread.handleSendResult(ActivityThread.java:3582) ************at android.app.ActivityThread.access$1300(ActivityThread.java:144) ************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327) ************at android.os.Handler.dispatchMessage(Handler.java:102) ************at android.os.Looper.loop(Looper.java:135) ************at android.app.ActivityThread.main(ActivityThread.java:5221) ************at java.lang.reflect.Method.invoke(Native Method) ************at java.lang.reflect.Method.invoke(Method.java:372) ************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) ************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
fichier xml pour la listview with fixed header :Code:
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 import android.app.Activity; import android.content.Intent; import android.database.MatrixCursor; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.Toast; import java.util.ArrayList; public class List_Of_Articles extends Fragment { View v ; ListView lv ; ImageButton AddBtn ; DataBase_Handler MyDB; MatrixCursor matrixCursor ; SimpleCursorAdapter adapter ; String[] from = new String[3]; int[] to = new int[3]; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { v = inflater.inflate(R.layout.list_articles_layout,container,false); MyDB = new DataBase_Handler(v.getContext()); lv = (ListView) v.findViewById(R.id.list); createTable(); AddBtn = (ImageButton) v.findViewById(R.id.add_article); AddBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(),Article.class); getActivity().startActivityForResult(intent, 5478); } }); return v ; } public void createTable () { String[] columns = new String[] { "_id", "Code Art", "Description" , "Price" }; matrixCursor= new MatrixCursor(columns); getActivity().startManagingCursor(matrixCursor); // add empty rows : matrixCursor.addRow(new Object[]{1, "", "", ""}); matrixCursor.addRow(new Object[] { 2,"","","" }); matrixCursor.addRow(new Object[] { 3,"","","" }); matrixCursor.addRow(new Object[] { 4,"","","" }); from = new String[] {getString(R.string.dataArtRef) ,getString(R.string.dataArtDesc) ,getString(R.string.dataArtPrice )}; to = new int[] { R.id.textViewCol1, R.id.textViewCol2 , R.id.textViewCol3}; adapter = new SimpleCursorAdapter(this.getActivity(), R.layout.row_article, matrixCursor, from, to, 0); lv.setAdapter(adapter); } public void onActivityResult(int requestCode, int resultCode, Intent data) { // get extra from the intent and stock them in tab String[] listOfArticle = data.getExtras().getStringArray("ArticleForScheda"); if (requestCode == 5478) { if (resultCode == Activity.RESULT_OK) { // add new row to the list of articles matrixCursor.addRow(new Object[]{listOfArticle[0], listOfArticle[1], listOfArticle[2]}); adapter.notifyDataSetChanged(); } } } }
fichier xml pour les ligne de la listview :Code:
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:id="@+id/linearLayout"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/add_article" android:background="#ffffff" android:src="@drawable/edit_add1" android:layout_gravity="left" android:paddingLeft="@dimen/abc_config_prefDialogWidth" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/linearLayout" android:id="@+id/linearLayout2"> <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="CODE_ART" android:textColor="#000000" android:textStyle="bold" android:textSize="15dp" /> <TextView android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="DESCRIPTION" android:textColor="#000000" android:textStyle="bold" android:textSize="15dp" /> <TextView android:id="@+id/textView3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="PRICE" android:textColor="#000000" android:textStyle="bold" android:textSize="15dp" /> </LinearLayout> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/linearLayout2"> </ListView> </RelativeLayout>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/listText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textColor="#222222" android:textSize="18sp" android:textStyle="bold" /> </LinearLayout>
j'ai résolu le problème c'est juste que se n'est pas la totalité des données qui ont passer d'une activité a une autre mais la moité et de plus j'ai oublier de définir le numéro de la ligne ou je veux ajouter les donnée dans la listview
j'ai remplacer
avec :Code:
1
2
3
4
5
6
7 Cursor cursor=MyDB.getArticle(id); cursor.moveToFirst(); for (int i=0 ; i<cursor.getCount ; i++) { tabOfArticleForScheda[i]=cursor.getString(i); }
et j'au ajouter le num de la ligne :Code:
1
2
3
4
5
6
7 Cursor cursor=MyDB.getArticle(id); cursor.moveToFirst(); for (int i=0 ; i<9 ; i++) { tabOfArticleForScheda[i]=cursor.getString(i); }
Code:matrixCursor.addRow(new Object[]{ 1 ,listOfArticle[0], listOfArticle[1], listOfArticle[2]});
Cool, dans ce cas marque le post RESOLU en cliquant sur :resolu:
Merci,
Christian