Java ANDROID:使用LAZYLIST从PHP JSON过滤Listview数据

Java ANDROID:使用LAZYLIST从PHP JSON过滤Listview数据,java,php,android,json,lazylist,Java,Php,Android,Json,Lazylist,我目前正在开发一个移动订购应用程序,我使用的是来自的listview来汇总我的订单,但我的问题是,我的数据库(Mysql)中的所有订单数据都显示出来了 我只想显示每个客户ID的订单 这是样本图像 --> OrderSum.java **OrderSum.java public class OrderSum extends Activity{ ListView list; TextView id; //// ver - id TextView name; //// na

我目前正在开发一个移动订购应用程序,我使用的是来自的listview来汇总我的订单,但我的问题是,我的数据库(Mysql)中的所有订单数据都显示出来了

我只想显示每个客户ID的订单

这是样本图像 -->

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 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("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();
            }
        } **
还有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;

    ?>

我不确定我是否完全理解您的要求-您从数据库中提取了一些行,对吗?然后“我想通过在订单摘要中获取客户id(文本视图中显示的客户id)来过滤这些数据”——我不知道该怎么做。你能试着把它换成一个问题吗?好的,我试着做一些屏幕截图,把我的问题换成另一个问题,,
    <?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;

    ?>