Android JSONObject to ListView -


I have a problem here, I am totally new on this.

What do I try to pass JSONObject to my adapter and make all the rows for that ListView inside my adapter

This is my code: < Pre> private static final string TAG_OS = "Android"; Protected void onPostExecute (JSONObject json) {try {JSONArray jArray = json.getJSONArray (TAG_OS); If (jArray! = Null) {for (int i = 0; i & lt; jArray.length (); i ++) {listdata.add (jArray.get (i) .toString ()); }} Menu_list = (list view) findViewById (R.id.menu_list); Menu Adapter Adapter = New Menu Adapter (Main Activity. This, New Array List [] {listdata}); Menu_list.setAdapter (adapter); } Hold (JasonX Express E) {e.printStackTrace (); }}

My adapter is:

  Public class menu adapter ArrayAdapter and lt; ArrayList & gt; {Personal Final Reference Reference; Private Final Array List [] Price; Public Menu Adapter (Reference Reference, Arrayist [] Value) {Super (Reference, R.Let.Menu_man, Value); This.context = context; this. Value = value; } @ Override public view getView (integer status, seeviewview, ViewGroup guardian) {layoutInfleter Inflator = (layout inferator) reference .getSystemService (reference. LAOUT_INFLATER_SERVICE); See row view- inflater.inflate (R.layout.menu_main, guardian, incorrect); If (position% 2 == 1) {rowView.setBackgroundColor (Color.RED); } And {rowView.setBackgroundColor (Color.BLUE); } See the return line; }   

I do not know how to populate the entire ListView, it's just a TextView with optional background. I still do not understand how to set one line after each other, a good example is not found

How can I fix this? : S

As you are using only one text field in your code, you have a custom adapter No need to make it, just for this, you can use Android's array adapter .

  ArrayAdapter & lt; String & gt; Adapter = new array adapter & lt; String & gt; (This, Android .RightSample_L_Litim_1_1, AndroidRID.Text1, Listadaata.Era ()); Menu_list.setAdapter (adapter);   

This snippet uses the default Android list layout and a text view that will take care of adding multiple rows for you.

Edit: It looks as if you need to use it to use BidAdaptor, you will need to create a class providing the basepapter and see the holder's Use this blog, which I wrote, it contains a class that extends Bidadaptor and uses a custom layout (.xml) file, how you will get the basic idea of ​​it

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -