package com.refresh.pos.ui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.refresh.pos.R;
import com.refresh.pos.core.Inventory;
import com.refresh.pos.database.NoDaoSetException;

public class ShowListActivity extends Activity {

	private Inventory inventory;
//	private List<Map<String, String>> stockList;
	List<HashMap<String, String>> stockList;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_showlist);

		try {
			
			inventory = Inventory.getInstance();
		} catch (NoDaoSetException e) {
			e.printStackTrace();
		}

//		List<Product> productList = inventory.getProductCatalog().getAllProduct();
//		Toast.makeText(ShowListActivity.this,productList.get(0).getName()+productList.get(0).getBarcode()+
//				productList.get(0).getId()+productList.get(0).getSalePrice(),
//				Toast.LENGTH_SHORT).show();
		
		stockList = inventory.getProductCatalog().getAllProductAsMap();
		
//		for (Product product : productList) {
//			Map<String, String> map = new HashMap<String, String>();
//	        map.put("_id", product.getId()+"");
// 	        map.put("name", product.getName());
// 	        map.put("barcode", product.getBarcode());
// 	        map.put("sale_price", product.getSalePrice()+"");
// 	        stockList.add(map);
//		}

		// listView1
		ListView lisView1 = (ListView) findViewById(R.id.listView1);

		SimpleAdapter sAdap;
		sAdap = new SimpleAdapter(ShowListActivity.this, stockList,
				R.layout.activity_column, new String[] { "name",
						"barcode","sale_price" }, new int[] { R.id.ColProductID,
						R.id.ColName, R.id.ColBarcode });
		lisView1.setAdapter(sAdap);

		final Button addProductButton = (Button) findViewById(R.id.addNewProduct);

		addProductButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent newActivity = new Intent(ShowListActivity.this,AddActivity.class);
				startActivity(newActivity);
			}
		});

	}

}

@@ -180,16 +180,41 @@
 Bundle;%0A
+import android.util.Log;%0A
 import a
@@ -227,24 +227,24 @@
 .view.View;%0A
-
 import andro
@@ -528,16 +528,44 @@
 entory;%0A
+%09private ListView lisView1;%0A
 //%09priva
@@ -1636,25 +1636,16 @@
 View1%0A%09%09
-ListView 
 lisView1
@@ -1959,16 +1959,19 @@
 (sAdap);
+%0A%09%09
 %0A%0A%09%09fina
@@ -2220,16 +2220,16 @@
 class);%0A
-
 %09%09%09%09star
@@ -2262,16 +2262,603 @@
 %09%7D%0A%09%09%7D);
+%0A%09%09final Button refreshButton = (Button) findViewById(R.id.refreshButton);%0A%09%09refreshButton.setOnClickListener(new View.OnClickListener() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void onClick(View v) %7B%0A//%09%09%09%09Log.v(%22%3E%3E%3E%3E%22,%22Refresh!%22);%0A%09%09%09%09stockList = inventory.getProductCatalog().getAllProductAsMap();%0A%09%09%09%09SimpleAdapter sAdap;%0A%09%09%09%09sAdap = new SimpleAdapter(ShowListActivity.this, stockList,%0A%09%09%09%09%09%09R.layout.activity_column, new String%5B%5D %7B %22name%22,%0A%09%09%09%09%09%09%09%09%22barcode%22,%22sale_price%22 %7D, new int%5B%5D %7B R.id.ColProductID,%0A%09%09%09%09%09%09%09%09R.id.ColName, R.id.ColBarcode %7D);%0A%09%09%09%09lisView1.setAdapter(sAdap);%0A%09%09%09%09%0A%09%09%09%7D%0A%09%09%7D);
 %0A%0A%09%7D%0A%0A%7D%0A

Add RefreshButton Function in ShowStockActivity