-
How can we prepare JSON Array by using List View in Android
about 9 years ago
-
about 9 years ago
Create custom Model/Bean Class and create ArrayList of Model/Bean class insted of String.
Suppose you create Model Class with name MyData and params are id,name,email.
Create Adapter with ArrayList.
set Text to CustomView from Mydata object and when you click on any List Item then write code to get object of MyData ArryList from clicked item position. and do what do do with MyData.
-
-
about 9 years ago
For more specific answer please elaborate your requirement .
-
-
about 9 years ago
Here is the code to create json array and json object.
try { // outer json object JSONObject mainObject = new JSONObject(); JSONArray arr=new JSONArray(); for(int i=0;i<size;i++)// size is listview size { JSONObject object=new JSONObject(); object.put("id","id"+i);// set id here object.put("name","name"+i); //set name here object.put("value","value"+i); // set value here arr.put(object); } mainObject.put("Array",arr); }catch(JsonException e) { }
If you want complete jsonobject than use mainObject If you want only jsonArray then use arr
-
3 Answer(s)