android - ArrayList not showing last item in listview -



android - ArrayList not showing last item in listview -

i storing values in arraylist as{india,pakisthan,srilanka,nepal,malasiya,australia,ireland} when set list baseadapter lastly element not showing lastly item in listview when listview extends device screen. showing india, pakisthan, srilanka, nepal, malasiaya , commonwealth of australia breaking , republic of ireland not showing. listfragment class

package com.example.mynavigationtab; import java.util.arraylist; import org.apache.http.namevaluepair; import org.apache.http.message.basicnamevaluepair; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; public class androidfragment extends listfragment { arraylist<countryobject> mcountry = new arraylist<countryobject>(); arraylist<string> mcoun = new arraylist<string>(); countryobject country = new countryobject(); androidadapter madapter; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { loadurl(); homecoming super.oncreateview(inflater, container, savedinstancestate); } @override public void onstart() { super.onstart(); getlistview().setchoicemode(listview.choice_mode_multiple); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); } public void loadurl() { arraylist<namevaluepair> pairs = new arraylist<namevaluepair>(); pairs.add(new basicnamevaluepair("naren", "naren")); new getjsondata().execute(getstring(r.string.tag_url),pairs,threadcode.thread_url, handler); } private handler handler = new handler() { @override public void handlemessage(message msg) { getactivity().removedialog(0); switch (msg.what) { case threadcode.thread_url: final string result = (string) msg.obj; loadjson(result); break; default: break; } } }; public void loadjson(string result) { seek { jsonobject mjson1 = new jsonobject(result); jsonarray mresult = mjson1.getjsonarray("result"); mcountry = new arraylist<countryobject>(); for(int i=0; i<mresult.length(); i++) { jsonobject mres = mresult.getjsonobject(i); jsonarray mcount = mres.getjsonarray("country"); jsonobject mcoun = mcount.getjsonobject(i); countryobject msetdata = new countryobject(); msetdata.setmcountry(mcoun.getstring("name")); mcountry.add(msetdata); countryobject msetdata1 = new countryobject(); msetdata1.setmcountry(mcoun.getstring("name1")); mcountry.add(msetdata1); countryobject msetdata2 = new countryobject(); msetdata2.setmcountry(mcoun.getstring("name2")); mcountry.add(msetdata2); countryobject msetdata3 = new countryobject(); msetdata3.setmcountry(mcoun.getstring("name3")); mcountry.add(msetdata3); countryobject msetdata4 = new countryobject(); msetdata4.setmcountry(mcoun.getstring("name4")); mcountry.add(msetdata4); countryobject msetdata5 = new countryobject(); msetdata5.setmcountry(mcoun.getstring("name5")); mcountry.add(msetdata5); countryobject msetdata6 = new countryobject(); msetdata6.setmcountry(mcoun.getstring("name6")); mcountry.add(msetdata6); countryobject msetdata7 = new countryobject(); msetdata7.setmcountry(mcoun.getstring("name7")); mcountry.add(msetdata7); countryobject msetdata8 = new countryobject(); msetdata8.setmcountry(mcoun.getstring("name8")); mcountry.add(msetdata8); } } grab (jsonexception e) { log.e("log_tag", "error parsing info " + e.tostring()); string mmessage = "error parsing json info server. please seek again."; showtoast(mmessage); } } public void showtoast(string message) { int duration = toast.length_short; toast toast = toast.maketext(getactivity(), message, duration); toast.show(); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); loadurl(); } }`

//adapter class

package com.example.mynavigationtab; import java.util.arraylist; import android.app.activity; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.textview; public class androidadapter extends baseadapter { arraylist<string> mcountry = new arraylist<string>(); context mcontext; textview mcountryname; public androidadapter(context androidfragment,arraylist<string> mcoun) { mcountry = mcoun; mcontext = androidfragment; } @override public int getcount() { homecoming mcountry.size(); } @override public object getitem(int position) { homecoming mcountry.get(position); } @override public long getitemid(int position) { homecoming mcountry.indexof(getitem(position)); } @override public view getview(int position, view convertview, viewgroup parent) { converview = null; if (convertview == null) { layoutinflater vi = (layoutinflater)mcontext.getsystemservice(mcontext.layout_inflater_service); convertview = vi.inflate(r.layout.adapter_list, parent,false); mcountryname = (textview) convertview.findviewbyid(r.id.textone); mcountryname.settext(mcountry.get(position)); } homecoming convertview; } }

// xml layout adapter_list.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <textview android:id="@+id/textone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="30sp" android:padding="2dp" android:textstyle="bold"/> </relativelayout> //json file { result: [ { country: [ { name: "india", name1: "pakisthan", name2: "bangaldesh", name3: "australia", name4: "ireland", name5: "srilanka", name6: "nepal", name7: "usa", name8: "russia" } ], states: [ { states: "tamil nadu", states1: "andhra", states2: "karnataka", states3: "kerala" } ], district: [ { district: "krishnagiri", district1: "dharmapuri", district2: "salem", district3: "hosur" } ] } ] }

may solve problem : if (convertview == null) { layoutinflater vi = (layoutinflater)mcontext.getsystemservice(mcontext.layout_inflater_service); convertview = vi.inflate(r.layout.adapter_list, parent,false); mcountryname = (textview) convertview.findviewbyid(r.id.textone); } mcountryname.settext(mcountry.get(position));//write after status

android listview arraylist

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -