Я в настоящее время разрабатываю мобильное приложение для заказа, и я использую listview из https://github.com/thest1/LazyList для сводки моих заказов, но моя проблема в том, что отображаются все данные заказов из моей базы данных (Mysql).
Я хочу показывать только заказы по идентификатору клиента
вот пример изображения
-> http://postimg.org/image/dnayd433x/
OrderSum.java
**OrderSum.java
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";///////////////////////
@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("http://192.168.43.52/MMOS/api/ordershow.php") ;
// jsonobject = JSONfunctions.getJSONfromURL( //192.168.43.52 /// 10.0.2.2
// ordershow, "GET", params);
//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();
}
} **
и для JSONFUNCTION
** открытый класс JSONfunctions {
public static JSONObject getJSONfromURL(String url) {
InputStream is = null;
String result = "";
JSONObject jArray = null;
// Download JSON data from URL
try {HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// Convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return jArray;
}
и код PHP
<?php
mysql_connect('localhost','root','')or die ('No Connection');
mysql_select_db('dbmoms');
//$o_od = $_GET['text_ordernumber'];
$sql ="SELECT * FROM orders"; // WHERE ord_num ='$o_od' "; //WHERE ord_num = '$ordnum'
$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;
?>
Я надеюсь, что вы можете помочь мне 🙂
заранее спасибо. 🙂
Задача ещё не решена.
Других решений пока нет …