Android List View Showing only one item from two

CialisItaly

New Member
I'am trying to make a ListView that contains two items (two textView's)Here is my code:Header XML:\[code\]<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/txtHeader" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:textStyle="bold" android:textSize="22dp" android:textColor="#FFFFFF" android:padding="10dp" android:text="Shoping List" android:background="#336699" /></LinearLayout>\[/code\]Hers is the row XML:\[code\]<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp"> <TextView android:id="@+id/prudctName" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textStyle="bold" android:textSize="22sp" android:textColor="#000000" /> <TextView android:id="@+id/productAmount" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textStyle="bold" android:textSize="22sp" android:textColor="#000000" /></LinearLayout>\[/code\]Here is the MAIN SCREEN XML:\[code\]<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF"> <ListView android:id="@+id/shoping_list" android:layout_width="fill_parent" android:layout_height="fill_parent" /></LinearLayout>\[/code\]Here is the class that represents the object containing the two filed:\[code\]public class ShopingListItem{ public String productName; public String procuctAmount; public ShopingListItem(String _productName,String _productAmount) { this.procuctAmount=_productAmount; this.productName=_productName; }}\[/code\]Here is the Adapter class:\[code\] public class ShopingListItemAdapter extends ArrayAdapter<ShopingListItem> { public Context context; public int layoutResourceId; public ShopingListItem[] items; public ShopingListItemAdapter(Context context,int layoutResourceId, ShopingListItem[] objects) { super(context, layoutResourceId, objects); this.context=context; this.layoutResourceId=layoutResourceId; this.items=objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ShopingListItemHolder holder = null; if(row==null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new ShopingListItemHolder(); holder.productName=(TextView)row.findViewById(R.id.prudctName); holder.productAmount=(TextView)row.findViewById(R.id.productAmount); row.setTag(holder); } else { holder = (ShopingListItemHolder)row.getTag(); } ShopingListItem item = items[position]; String amount = item.procuctAmount; String name = item.productName; TextView v = holder.productAmount; TextView vv = holder.productName; holder.productAmount.setText(amount); holder.productName.setText(name); return row; } static class ShopingListItemHolder { TextView productName; TextView productAmount; } }\[/code\]Here is the main activity:\[code\]public class ShopingListActivity extends Activity{ private ListView listView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shoping_list_screen); //fill list with temp data ShopingListItem[] items = fillData(); ShopingListItemAdapter adapter = new ShopingListItemAdapter(this, R.layout.listview_item_row, items); listView1 = (ListView)findViewById(R.id.shoping_list); View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null); listView1.addHeaderView(header); listView1.setAdapter(adapter); } private ShopingListItem[] fillData() { ShopingListItem[] items = new ShopingListItem[] { new ShopingListItem("Bamba", "2"), new ShopingListItem("Bisli", "12"), new ShopingListItem("Shoko", "3"), new ShopingListItem("Yello Cheese", "2"), new ShopingListItem("Marak", "7"), new ShopingListItem("Cola", "2"), new ShopingListItem("Orez", "3"), new ShopingListItem("Kaki", "9"), new ShopingListItem("Battery", "1"), new ShopingListItem("Bla", "1"), new ShopingListItem("Bla bla", "100"), new ShopingListItem("bbb", "200"), new ShopingListItem("Red", "2"), }; return items; }}\[/code\]The result of the code is a list but with only one item (the name) the amount isnt add'dCan anyone find the problem?
 
Back
Top