java - Display data fromSQLite in TableLayout -
please me...i'm new android development , trying retrieve sqlite
data tablelayout
. program retrieve information belongs name , display in tablelayout
. when click button
in workdetailstable.java
, crashed.
displaydata.java
public class displaydata extends appcompatactivity { tablelayout table_layout; infoapi sqlcon; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.displaydata); mydatabasehelper db=new mydatabasehelper(this); infoapi i1=new infoapi(this); sqlcon=new infoapi(this); setrequestedorientation(activityinfo.screen_orientation_landscape); table_layout = (tablelayout) findviewbyid(r.id.tablelayout1); final string name1 = getintent().getextras().getstring("name"); // pass workdetailstable.java toast.maketext(getapplicationcontext(), name1, toast.length_short).show(); if (name1.equals("x x x")) ; { buildtable(name1); } } private void buildtable(string name) { sqlcon.open(); cursor c = sqlcon.readentry(name); //refer infoapi int rows = c.getcount(); int cols = c.getcolumncount(); c.movetofirst(); // outer loop (int = 0; < rows; i++) { tablerow row = new tablerow(this); row.setlayoutparams(new viewgroup.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.wrap_content)); // inner loop (int j = 0; j < cols; j++) { textview tv = new textview(this); tv.setlayoutparams(new viewgroup.layoutparams(viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content)); tv.setbackgroundresource(r.drawable.cell_shape); tv.setgravity(gravity.center); tv.settextsize(18); tv.setpadding(0, 5, 0, 5); tv.settext(c.getstring(j)); row.addview(tv); } c.movetonext(); table_layout.addview(row); } sqlcon.close(); } }
infoapi.java
public cursor readentry(string name) { string selectquery = ("select weather,date,status "+mydatabasehelper.table_info+"where name= ?"); database=dbhelper.getwritabledatabase(); cursor c = database.query(mydatabasehelper.table_info,new string[]{mydatabasehelper.id,mydatabasehelper.name,mydatabasehelper.weather,mydatabasehelper.date,mydatabasehelper.status},mydatabasehelper.name+"=?", new string[] { string.valueof(name)}, null, null, null, null); if (c != null) { c.movetofirst(); } return c; }
displaydata.xml
<?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" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <textview android:id="@+id/weather" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="weather" /> <textview android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="date" /> <textview android:id="@+id/status" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="status" /> </linearlayout> <scrollview android:layout_width="match_parent" android:layout_height="match_parent" > <tablelayout android:id="@+id/tablelayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:shrinkcolumns="*" android:stretchcolumns="*" > </tablelayout> </scrollview> </linearlayout>
logcat error
10-10 08:52:04.691 6844-6844/com.example.project.project e/androidruntime﹕ fatal exception: main process: com.example.project.project, pid: 6844 java.lang.arithmeticexception: divide 0 @ android.widget.tablelayout.mutatecolumnswidth(tablelayout.java:584) @ android.widget.tablelayout.shrinkandstretchcolumns(tablelayout.java:573) @ android.widget.tablelayout.measurevertical(tablelayout.java:471) @ android.widget.tablelayout.onmeasure(tablelayout.java:436) @ android.view.view.measure(view.java:18788) @ android.widget.scrollview.measurechildwithmargins(scrollview.java:1283) @ android.widget.framelayout.onmeasure(framelayout.java:194) @ android.widget.scrollview.onmeasure(scrollview.java:340) @ android.view.view.measure(view.java:18788) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5951) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1465) @ android.widget.linearlayout.measurevertical(linearlayout.java:748) @ android.widget.linearlayout.onmeasure(linearlayout.java:630) @ android.view.view.measure(view.java:18788)
are error came infoapi? how fix this? suggestions woukd appreciated.
for information, have 5 data in info table (id,name,weather,date,status), want retrieve weather,date , status only.
remove 2 lines in table layout
android:shrinkcolumns="*" android:stretchcolumns="*"
Comments
Post a Comment