ANDROID: получить общую сумму столбца из списка просмотра LazyList (thest1 / LazyList)

В настоящее время я разрабатываю приложение для заказа нашего проекта и использую LazyList Listview от https://github.com/thest1/LazyList

В моем списке просмотра у меня есть цена textView, я хочу суммировать всю цену textView в моем списке просмотра и поместить ее в textView TotalSum.

Вот код

public class OrderSum extends Activity{

ListView list;
TextView id;  //// ver - id
TextView name; //// name - name
TextView quan; ////  api - desc
TextView price; ////  price
TextView order_num; ////  price
TextView cust_num; ////  price
ImageView image;

TextView items;
TextView empty;
TextView home_ornum;
TextView cust_name;

ImageButton addOrder;
ImageButton proceed;

DigitalClock time;
TextView os;

TextView o_total;// Declare Variables
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
LvOrderSumAdapter adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String ID = "id";
static String NAME = "ord_name";
static String PRICE = "ord_price";
static String QTY = "ord_qty";
static String CUSTID = "customer_id";
static String ORDER = "ord_num";
static String PXQ = "price_x_quan";
static String IMAGE = "image";
static String OR = "text_ordernumber";
static String ON = "text_name";
static String TP = "t_price";

private static String ordershow = "http://192.168.43.52/MMOS/api/ordershow.php";
///////////////////////

@SuppressLint({ "SimpleDateFormat", "NewApi" })
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.order_summary);

// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();

/**Unique ID / Customer Id***/
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
/**
* Hashmap to load data from the Sqlite database
**/
HashMap user = new HashMap();
user = db.getUserDetails();final TextView unique_id = (TextView) findViewById(R.id.o_custnum);
unique_id.setText((CharSequence) user.get("uid"));

/**END**/

/** DATE VIEW***/
TextView h_date = (TextView) findViewById(R.id.o_date);
Calendar c = Calendar.getInstance();
SimpleDateFormat format1;

format1 = new SimpleDateFormat("MMMM dd,yyyy");
// format2 = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss");

h_date.setText(format1.format(c.getTime()) );
/** END DATE VIEW***/cust_name = (TextView) findViewById(R.id.DisplaycustName);
home_ornum = (TextView) findViewById(R.id.Displayordernum);
time = (DigitalClock) findViewById(R.id.o_time);Intent myIntent = getIntent();
home_ornum.setText(myIntent.getStringExtra("text_ordernumber")); //order number is the TextView
cust_name.setText(myIntent.getStringExtra("text_name")); //tv is the TextViewitems= (TextView) findViewById(R.id.DisplayTotalItems);

/***************Custom Font***/
Typeface myCustomFont = Typeface.createFromAsset(getAssets(), "fonts/MavenPro.otf");
cust_name.setTypeface(myCustomFont);
home_ornum.setTypeface(myCustomFont);
time.setTypeface(myCustomFont);
h_date.setTypeface(myCustomFont);
/***************Custom Font**************/addOrder = (ImageButton) findViewById(R.id.btn_add);
addOrder.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(OrderSum.this,
Categories.class);
startActivity(myIntent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);

}
});/***************************PROCEED BUTTON***************************/
proceed = (ImageButton) findViewById(R.id.btn_proceed);
proceed.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(OrderSum.this,
OrderInformation.class);
startActivity(myIntent);
// uniq id , order no , date , name

//  final TextView d_date = (TextView) findViewById(R.id.o_date);
Intent ord_in = new Intent ( OrderSum.this, OrderInformation.class );
ord_in.putExtra ( "text_order", home_ornum.getText().toString() );
// ord_in.putExtra ( "text_date", d_date.getText().toString() );
ord_in.putExtra ( "text_custName", cust_name.getText().toString() );
ord_in.putExtra ( "text_items", items.getText().toString() );
startActivity(ord_in);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);}
});
/***************************PROCEED BUTTON***************************//**for the ROOF2**/
final ActionBar actionBar = getActionBar();
BitmapDrawable background = new BitmapDrawable
(BitmapFactory.decodeResource(getResources(), R.drawable.roof2));
///background.setTileModeX(android.graphics.Shader.TileMode.REPEAT);
actionBar.setBackgroundDrawable(background);
/**end for the ROOF2**/} /// end of OnCreate@Override
public void onBackPressed() {
super.onBackPressed();
/*Intent myIntent = new Intent(OrderSum.this,
Home.class);
startActivity(myIntent);*/
TextView on = (TextView) findViewById(R.id.Displayordernum);
Intent home_in = new Intent ( OrderSum.this, Home.class );
home_in.putExtra ( "text_ordernumber", on.getText().toString() );
startActivity(home_in);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);

}// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> {

@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(OrderSum.this);
// Set progressdialog title
mProgressDialog.setTitle("Your orders");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}@Override
protected Void doInBackground(Void... params) {

TextView custname = (TextView) findViewById(R.id.DisplaycustName);
TextView homeornum = (TextView) findViewById(R.id.Displayordernum);

Intent home_in = getIntent();
homeornum.setText(home_in.getStringExtra("text_ordernumber")); //tv is the TextView
custname.setText(home_in.getStringExtra("text_name")); //name is the TextView// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
JSONObject jsonobject = JSONfunctions.getJSONfromURL(ordershow) ;

//jsonobject = JSONfunctions.getJSONfromURL(,)
try {
// Locate the array name in JSON==
jsonarray = jsonobject.getJSONArray("orders");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
/* from db orders = id,ord_name,ord_desc,
ord_price,ord_qty,customer_id,ord_num,price_x_quan , image  jsonobjecy = from db*/
map.put("id", jsonobject.getString("id"));
map.put("ord_name", jsonobject.getString("ord_name"));
map.put("ord_price", jsonobject.getString("ord_price"));
map.put("ord_qty", jsonobject.getString("ord_qty"));
map.put("customer_id", jsonobject.getString("customer_id"));
map.put("ord_num", jsonobject.getString("ord_num"));
map.put("price_x_quan", jsonobject.getString("price_x_quan"));
map.put("image", jsonobject.getString("image"));
map.put("text_ordernumber",home_in.getStringExtra("text_ordernumber"));
map.put("text_name",home_in.getStringExtra("text_name"));

// Set the JSON Objects into the array
arraylist.add(map);

}} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}

return null;
}

@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listOrderSummary);

// Pass the results into ListViewAdapter.java
adapter = new LvOrderSumAdapter(OrderSum.this, arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);

listview.getAdapter().getCount();
String count = ""+listview.getAdapter().getCount();
items.setText(count);// Close the progressdialog
mProgressDialog.dismiss();
}
}
///

}

Вот код для BaseAdapter, ListViewAdapter.java

public class ListViewAdapter extends BaseAdapter{
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();public ListViewAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}public int getCount() {
return data.size();
}

public Object getItem(int position) {
return null;
}

public long getItemId(int position) {
return 0;
}

@SuppressLint("ViewHolder")
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView id;
TextView name;
TextView desc;
TextView price;
TextView iUrl; /// image URL
TextView iWebUrl ; //imgage kay chels
ImageView image;inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View itemView = inflater.inflate(R.layout.listview_v, parent, false);
//View itemView = inflater.inflate(R.layout.listview_menu, parent, false);// Get the position
resultp = data.get(position);// Locate the TextViews in listview_item.xml
id = (TextView) itemView.findViewById(R.id.id);
name = (TextView) itemView.findViewById(R.id.name);
desc = (TextView) itemView.findViewById(R.id.desc);
price = (TextView) itemView.findViewById(R.id.price);
iUrl = (TextView) itemView.findViewById(R.id.imageUrl);
iWebUrl = (TextView) itemView.findViewById(R.id.imgUrlWeb);
// Locate the ImageView in listview_item.xml
image = (ImageView) itemView.findViewById(R.id.imageView1);

// Capture position and set results to the TextViews
id.setText(resultp.get(C_Pastries.ID));
name.setText(resultp.get(C_Pastries.NAME));
price.setText(resultp.get(C_Pastries.PRICE));
desc.setText(resultp.get(C_Pastries.DESCRIPTION));

iUrl.setText(resultp.get(C_Pastries.IMAGE));
iWebUrl.setText(resultp.get(C_Pastries.IMGIMG));
//ordnum.setText(resultp.get(Products.EX));

// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
imageLoader.DisplayImage(resultp.get(C_Pastries.IMAGE), image);// Capture ListView item click
itemView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v ) {
// Get the positionresultp = data.get(position);

Intent intent = new Intent(context, Menu_Clicked.class);

// Pass all data rank
//String listValue = (String) data.get(position).get(Products.aa);
intent.putExtra("id", resultp.get(C_Pastries.ID));

intent.putExtra("name", resultp.get(C_Pastries.NAME));
// Pass all data country
intent.putExtra("description", resultp.get(C_Pastries.DESCRIPTION));
// Pass all data population
intent.putExtra("price",resultp.get(C_Pastries.PRICE));
// Pass all data flag
intent.putExtra("image", resultp.get(C_Pastries.IMAGE));
intent.putExtra("imgimg", resultp.get(C_Pastries.IMGIMG));
// Start SingleItemView Class
intent.putExtra("text_ordernumber",resultp.get(C_Pastries.EX));

context.startActivity(intent);}
});
return itemView;
}
}

Вот код php ordershow.php

    <?php
mysql_connect('localhost','root','')or die ('No Connection');
mysql_select_db('dbmoms');$sql ="SELECT * FROM orders";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$arr['orders'][]= $row;

}
$json = json_encode($arr);

$json_encoded_string = json_encode($arr);
$json_encoded_string = str_replace("\\/", '/', $json_encoded_string);

echo $json_encoded_string;

?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]