android - Activity with ListView and other elements -
i dont know how set activity layour right. have layout button @ top , when click want populate listview present data(like history of ordered pizzas). when click button this:
i dont understand why button keeps copying. want 1 @ top.
activity_tab_history.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.example.tomek.pizzaservice.tabhistoryactivity"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="refresh" android:id="@+id/buttrefresh" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:onclick="buttrefreshaction" /> <listview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listview" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:clickable="false" android:layout_below="@+id/textviewitem" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new text" android:id="@+id/textviewitem" android:layout_below="@+id/buttrefresh" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> </relativelayout>
code:
public void buttrefreshaction(view view){ listview.setadapter(loaddatafromdatabase()); } private arrayadapter<string> loaddatafromdatabase(){ toast.maketext(tabhistoryactivity.this, "loading orders", toast.length_short).show(); arrayadapter<string> arrayadapter = new arrayadapter<string>(this, r.layout.activity_tab_history, r.id.textviewitem); random rand = new random(); for(int i=0; i<10; i++){ arrayadapter.add("order date: 2000:01:" +(01+i)+ ", pizza: " + (rand.nextint(15)+1) + ". pizza name bla bla bla" + " status: somthin"); } toast.maketext(tabhistoryactivity.this, "completed loading orders", toast.length_short).show(); return arrayadapter; }
you telling adapter each row has same layout whole thing.
look @
arrayadapter<string> arrayadapter = new arrayadapter<string>(this, r.layout.activity_tab_history, r.id.textviewitem);
the second item given should layout row. should this
arrayadapter<string> arrayadapter = new arrayadapter<string>(this, r.layout.my_row_template, r.id.textviewitem);
and row template layout file shows want each row like, on other hand this
arrayadapter<string> arrayadapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, android.r.id.text1);
which use default android row layout of line of text
Comments
Post a Comment