Php ANDROID:从LazyList列表视图(thest1/LazyList)获取列的总和
我目前正在为我们的项目开发一个订购应用程序,我正在使用来自的LazylistListView 在我的listview中,我有一个textView价格,我想要的是将我的listview中的所有textView价格相加,并将其放入textView TotalSum 这是密码Php ANDROID:从LazyList列表视图(thest1/LazyList)获取列的总和,php,android,listview,android-listview,lazylist,Php,Android,Listview,Android Listview,Lazylist,我目前正在为我们的项目开发一个订购应用程序,我正在使用来自的LazylistListView 在我的listview中,我有一个textView价格,我想要的是将我的listview中的所有textView价格相加,并将其放入textView TotalSum 这是密码 public class OrderSum extends Activity{ ListView list; TextView id; //// ver - id TextView name; //// name - nam
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 TextView
items= (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();
}
}
///
}
公共类OrderSum扩展活动{
列表视图列表;
TextView id;///ver-id
TextView名称;///name-name
TextView;///api-desc
text查看价格;///price
text查看订单数量;///价格
text查看客户数量;/////价格
图像视图图像;
文本视图项目;
文本视图为空;
文本视图主页;
TextView客户名称;
图像按钮添加顺序;
图像按钮继续;
数字时钟时间;
TextView操作系统;
文本视图o_总计;
//声明变量
JSONObject JSONObject;
JSONArray JSONArray;
列表视图列表视图;
LVO适配器;
进程对话框;
ArrayList ArrayList;
静态字符串ID=“ID”;
静态字符串NAME=“ord_NAME”;
静态字符串PRICE=“订单价格”;
静态字符串数量=“订单数量”;
静态字符串CUSTID=“customer\u id”;
静态字符串ORDER=“ord_num”;
静态字符串PXQ=“price\u x\u quan”;
静态字符串IMAGE=“IMAGE”;
静态字符串或=“text\u ordernumber”;
静态字符串ON=“text\u name”;
静态字符串TP=“t_price”;
私有静态字符串ordershow=”http://192.168.43.52/MMOS/api/ordershow.php";
///////////////////////
@SuppressLint({“SimpleDataFormat”,“NewApi”})
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(右布局、订单摘要);
//执行下载JSON异步任务
新建下载JSON().execute();
/**唯一ID/客户ID***/
DatabaseHandler db=新的DatabaseHandler(getApplicationContext());
/**
*Hashmap从Sqlite数据库加载数据
**/
HashMap用户=新建HashMap();
user=db.getUserDetails();
最终TextView unique_id=(TextView)findViewById(R.id.o_custnum);
唯一的_id.setText((CharSequence)user.get(“uid”);
/**结束**/
/**日期视图***/
TextView h_日期=(TextView)findViewById(R.id.o_日期);
Calendar c=Calendar.getInstance();
简化格式1;
format1=新的SimpleDataFormat(“MMMM dd,yyyy”);
//格式2=新的简化格式(“dd-MM-yyy-HH-MM-ss”);
h_date.setText(format1.format(c.getTime());
/**结束日期视图***/
cust_name=(TextView)findviewbyd(R.id.DisplaycustName);
home_ornum=(TextView)findViewById(R.id.Displayordernum);
时间=(数字时钟)findViewById(R.id.o_时间);
Intent myIntent=getIntent();
home_ornum.setText(myIntent.getStringExtra(“text_ordernumber”);//订单号是文本视图
cust_name.setText(myIntent.getStringExtra(“text_name”);//电视是文本视图
items=(TextView)findViewById(R.id.DisplayTotalItems);
/***************自定义字体***/
Typeface myCustomFont=Typeface.createFromAsset(getAssets(),“fonts/MavenPro.otf”);
客户名称.设置字体(myCustomFont);
主页字体(myCustomFont);
time.setTypeface(myCustomFont);
日期设置字体(myCustomFont);
/***************自定义字体************/
addOrder=(ImageButton)findViewById(R.id.btn\u add);
addOrder.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
Intent myIntent=新Intent(OrderSum.this,
类别(类别),;
星触觉(myIntent);
覆盖转换(R.anim.slide\u in\u left,R.anim.slide\u out\u left);
}
});
/***************************继续按钮***************************/
继续=(图像按钮)findViewById(R.id.btn\u继续);
继续.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
Intent myIntent=新Intent(OrderSum.this,
OrderInformation.class);
星触觉(myIntent);
//uniq id、订单号、日期、名称
//最终文本视图d_日期=(文本视图)findViewById(R.id.o_日期);
Intent ord_in=新Intent(OrderSum.this,OrderInformation.class);
ord_in.putExtra(“文本顺序”,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());
星触觉(ord_in);
覆盖转换(R.anim.slide\u in\u left,R.anim.slide\u out\u left);
}
});
/***************************继续按钮***************************/
/**对于屋顶2**/
最终ActionBar ActionBar=getActionBar();
BitmapDrawable后台=新的BitmapDrawable
(BitmapFactory.decodeResource(getResources(),R.drawable.root2));
///setTileModeX(android.graphics.Shader.TileMode.REPEAT);
actionBar.setBackgroundDrawable(背景);
/**到屋顶为止**/
}///OnCreate结束
@凌驾
public void onBackPressed(){
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 position
resultp = 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
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;
?>