android - How to set in a ListView text using List -
im starting @ android development , im interested in learn. im making android app administration of 1 farm. need create listview show me administrator has buyed. so, trying set listview that.. follow vogella's tutorial (http://www.vogella.com/tutorials/androidlistview/article.html). so, created class called "newlistviewadapter created xml file called "newlistviewadapter" , called in listfragment.
the question have how handle list, created list of compras objects , im trying set every textview in xml file dont know right way. can tell me how that?
i next vogella's tutorial works arrays , im trying utilize list.
following files:
newlistviewadapter
package com.example.projectcandy.adapter; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.textview; import com.example.projectcandy.r; import java.util.list; public class newlistviewadapter extends arrayadapter<list> { private textview tv1; private textview tv2; private textview tv3; private textview tv4; private textview tv5; private textview tv6; private final context context; private final list values; public newlistviewadapter(context context, list values) { super(context, r.layout.newlistview, values); this.context = context; this.values = values; } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(r.layout.newlistview, parent, false); tv1 = (textview) rowview.findviewbyid(r.id.textview9); tv2 = (textview) rowview.findviewbyid(r.id.textview10); tv3 = (textview) rowview.findviewbyid(r.id.textview11); tv4 = (textview) rowview.findviewbyid(r.id.textview12); tv5 = (textview) rowview.findviewbyid(r.id.textview13); tv1.settext((integer) values.get(1)); tv2.settext((integer) values.get(1)); tv3.settext((integer) values.get(1)); tv4.settext((integer) values.get(1)); tv5.settext((integer) values.get(1)); tv6.settext((integer) values.get(1)); homecoming rowview; } }
xml file
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp"> <linearlayout android:orientation="vertical" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingright="5dp" android:layout_weight="1"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/vendedor" android:id="@+id/textview" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/fechadecompra" android:id="@+id/textview3" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/peso_compra" android:id="@+id/textview4" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/cantidad" android:id="@+id/textview5" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/ubicacion_potrero" android:id="@+id/textview6" /> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingleft="5dp" android:layout_weight="1"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="texto mas laaaaaaaaargo" android:id="@+id/textview9" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/textview10" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/textview11" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/textview12" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/textview13" /> </linearlayout> </linearlayout>
implementation in listfragment
list <compra> compras = db.getallcompras(id_user); newlistviewadapter adapter = new newlistviewadapter(getactivity(), compras); setlistadapter(adapter); getlistview(); registerforcontextmenu(getlistview());
my plans show listview if user touch 1 element of listview user can take if modify or delete , need "compra" id. thats why im showing info , need take id. modify or delete it.
thanks.
to handle list item click in android can user onlistitemclick method. 1 scenario of handling modify , or delete alternative have alert dialog pop options. can decide take user activity , handle modification , deletion of object there. whatever works best you.
android xml listview android-listview
No comments:
Post a Comment