java - Display SQLite data in a ListView inside a Fragment -


i need code. want display qlite data listview inside fragment.i have 3 fragment 3 table display data in listview. in case, 3 tables, 1 of them main table. table named "estate". estate table, have division_id become primary key , foreign key table. so, when run application, user must click 1 value estate display in listview, display other data tables. learn many tutorial, still stuck in code. helping me solve problem. when run application, result force closed. here code.

estate.java

public class estate { 

//public string estate_id; private integer division_id; private string division_name;

public estate(){}

public int getdivision_id(){ return division_id;} public void setdivision_id(int division_id) { this.division_id = division_id;}

  public string getdivision_name(){           return division_name;}      public 

void setdivision_name(string division_name) { this.division_name = division_name;} /* public string getdivision(){ return division;} public void setdivision(string division) { this.division = division;} */ public estate(string division_name, string division_id) { super(); this.division_name = division_name; // this.division = division; this.division_id=integer.parseint(division_id); // this.estate_id=integer.parseint(estate_id); }}

then listadapaterestate.java

public class listadapterestate extends arrayadapter {

list<estate> estatelist;  public listadapterestate(context context, int resource,list<estate> list ) {     super(context, resource);     estatelist = list; }  static class layouthandler{     textview txtdivisionid,txtdivisionname; }  @override public int getcount() {     return estatelist.size(); }  @override public object getitem(int position) {     return estatelist.get(position); }   @override public view getview(int position, view convertview, viewgroup parent) {     view mview = convertview;     layouthandler layouthandler;     if(mview==null){         layoutinflater layoutinflater = (layoutinflater) this.getcontext().getsystemservice(context.layout_inflater_service);         mview = layoutinflater.inflate(r.layout.list_row_estate,parent,false);         layouthandler = new layouthandler();         layouthandler.txtdivisionid = (textview)mview.findviewbyid(r.id.adapter_text_id);         layouthandler.txtdivisionname = (textview)mview.findviewbyid(r.id.adapter_text_estate);           mview.settag(layouthandler);     }else {         layouthandler = (layouthandler) mview.gettag();     }     estate dataestate = (estate) this.getitem(position);     layouthandler.txtdivisionid.settext(dataestate.getdivision_id());     layouthandler.txtdivisionname.settext(dataestate.getdivision_name());      return mview; } } 

lihatdataestate.java

extends fragmentactivity { private estate estatedetail; private mysqlitehelper dbhelper; private list estatelist; private listadapterestate estatelistadapter; /** * attention: auto-generated implement app indexing api. * see https://g.co/appindexing/androidstudio more information. */ private googleapiclient client;

@requiresapi(api = build.version_codes.m) public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view mview = inflater.inflate(r.layout.activity_lihat_data_estate, container, 

false); listview listview = (listview) mview.findviewbyid(r.id.listcollege); estatelist = new arraylist<>(); dbhelper = new mysqlitehelper(getcontext()); dbhelper.getreadabledatabase(); cursor cursor = dbhelper.getalldataestate(); if (cursor.movetofirst()) { { string estatedivision_id, estatedivision_name; estatedivision_id = cursor.getstring(cursor.getcolumnindex("division_id")); estatedivision_name = cursor.getstring(cursor.getcolumnindex("division_name")); estate estate = new estate(estatedivision_id, estatedivision_name); estatelist.add(estate); } while (cursor.movetonext()); } estatelistadapter = new listadapterestate(getcontext(), r.layout.list_row_estate, estatelistadapter); listview.setadapter(estatelistadapter); return mview; }

/* public void onbackpressed(){     intent = new intent (lihatdataestate.this, mainactivity.class);     startactivity(i);     finish();  } 

*/ }

list_row_estate.xml

<linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="horizontal"     android:weightsum="3">      <textview         android:id="@+id/adapter_text_estate"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="2.24"         android:gravity="left"         android:padding="5dp"         android:textstyle="bold"         android:text="estate"         android:textsize="14sp" />      <textview         android:id="@+id/adapter_text_id"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:gravity="center"         android:padding="5dp"         android:textstyle="bold"         android:text="id"         android:textsize="14sp" /> </linearlayout>    </linearlayout> 

activity_lihat_data_estate.xml

<textview     android:id="@+id/cources_title"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="estate name"     android:textcolor="#429ed7"     android:textsize="12sp"     android:visibility="gone"     android:textstyle="bold" />    <listview     android:id="@+id/listcollege"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:visibility="gone"     android:layout_margintop="8dp" > </listview> <imageview     android:id="@+id/borderimg"     android:layout_width="fill_parent"     android:layout_height="1dp"     android:layout_alignleft="@+id/cources_title"     android:layout_below="@+id/cources_title"     android:background="#429ed7" />  <progressbar     android:id="@+id/procollagelist"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center|bottom"     android:visibility="visible" /> 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -