Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中始终从ListView列表中获取最后一个值_Android_Android Listview_Custom Adapter - Fatal编程技术网

在android中始终从ListView列表中获取最后一个值

在android中始终从ListView列表中获取最后一个值,android,android-listview,custom-adapter,Android,Android Listview,Custom Adapter,我制作了一个ListView,我想在它的ItemClickListener上发送一个值,我使用自定义适配器尝试了以下操作,但每次我在单击任何ListItem时都会得到最后一个项目的值,我尝试了以下操作,我发布了我的适配器和ListView的click事件,请告诉我错误在哪里,谢谢 **Activity** **Activity** import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayLis

我制作了一个ListView,我想在它的ItemClickListener上发送一个值,我使用自定义适配器尝试了以下操作,但每次我在单击任何ListItem时都会得到最后一个项目的值,我尝试了以下操作,我发布了我的适配器和ListView的click事件,请告诉我错误在哪里,谢谢

**Activity**

**Activity**

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.epe.yehki.adapter.BuyingRequestAdapter;
import com.epe.yehki.adapter.QuoteAdapter;
import com.epe.yehki.backend.BackendAPIService;
import com.epe.yehki.uc.Header;
import com.epe.yehki.util.Const;
import com.epe.yehki.util.Pref;
import com.epe.yehki.util.Utils;
import com.example.yehki.R;

public class BuyingreqActivity extends Activity implements OnClickListener {
    Button viewReq, postReq;
    EditText productName;
    TextView productCategory;
    TextView expTime;
    TextView productDesc;
    TextView estOrderQty;
    ImageView proImg;
    Button send;
    ImageView iv_fav_menu;
    private int flag = 1;
    ScrollView scr_post;
    RelativeLayout scr_view;
    RelativeLayout quote_view;
    private ProgressDialog pDialog;
    String viewURL, postURL;
    JSONObject jsonObj;
    String quote_id, buyerID;
    JSONArray requestes = null;
    JSONArray quotes = null;
    ArrayList<HashMap<String, String>> reqList;
    ArrayList<HashMap<String, String>> queList;
    private BuyingRequestAdapter buyingRequestContent;
    private QuoteAdapter quoteAdapter;
    RelativeLayout rl_botm;
    ListView lv;
    Header header;
    Calendar dateandtime;
    private static final int PICK_FROM_CAMERA = 100;
    private static final int PICK_FROM_GALLERY = 200;
    private Uri picUri;
    int la, lo;
    final int CAMERA_CAPTURE = 1;
    private static String fileName;
    Intent in = null;
    ListView quoteList;

    private String imagePath;
    private Uri imageUri;
    String buyer_request_id, reqID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_buying_request);

        InitializeView();
        productCategory.setOnClickListener(this);
        send.setOnClickListener(this);
        expTime.setOnClickListener(this);
        proImg.setOnClickListener(this);

        dateandtime = Calendar.getInstance(Locale.US);
        header.back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
            }
        });

        reqList = new ArrayList<HashMap<String, String>>();
        queList = new ArrayList<HashMap<String, String>>();
        viewReq.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                flag = 2;
                reqList.clear();
                iv_fav_menu.setBackgroundResource(R.drawable.tab_two_fav);

                callGetQuoteListAsyncTask();

                scr_view.setVisibility(View.VISIBLE);
                quote_view.setVisibility(View.GONE);
                rl_botm.setVisibility(View.GONE);
                scr_post.setVisibility(View.GONE);

            }
        });

        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                in = new Intent(getApplicationContext(), BuyingRequestDetailActivity.class);

                // getting ProductId from the tag...

                reqID = reqList.get(position).get(Const.TAG_BUYING_REQUEST_ID);
                System.out.println(":::::::::::::::;;THE INTENT FOR THE resuest DETIALS ACTIVITY=================" + reqID);
                in.putExtra(Const.TAG_BUYING_REQUEST_ID, reqID);
                in.putExtra(Const.TAG_QUOTE_ID, quote_id);
                System.out.println("::::::::::::Buyer Id and Request Id::::::::;" + reqID + " ====>" + quote_id);
                startActivity(in);
            }

        });
        quoteList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                in = new Intent(getApplicationContext(), QuoteDetailActivity.class);

                // getting ProductId from the tag...

                reqID = queList.get(position).get(Const.TAG_BUYING_REQUEST_ID);
                quote_id = queList.get(position).get(Const.TAG_QUOTE_ID);
                System.out.println(":::::::::::::::;;THE INTENT FOR THE resuest DETIALS ACTIVITY=================" + reqID);
                in.putExtra(Const.TAG_BUYING_REQUEST_ID, reqID);
                in.putExtra(Const.TAG_QUOTE_ID, quote_id);
                System.out.println("::::::::::::Buyer Id and Request Id::::::::;" + reqID + " ====>" + quote_id);
                startActivity(in);
            }
        });
        postReq.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                flag = 1;
                iv_fav_menu.setBackgroundResource(R.drawable.tab_one_fav);
                quote_view.setVisibility(View.GONE);
                scr_post.setVisibility(View.VISIBLE);
                rl_botm.setVisibility(View.VISIBLE);
                scr_view.setVisibility(View.GONE);

            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        case R.id.tv_pro_cat:

            break;
        case R.id.tv_pro_exp_tym:

            DatePickerDailog dp = new DatePickerDailog(BuyingreqActivity.this, dateandtime, new DatePickerDailog.DatePickerListner() {

                @Override
                public void OnDoneButton(Dialog datedialog, Calendar c) {
                    datedialog.dismiss();
                    dateandtime.set(Calendar.YEAR, c.get(Calendar.YEAR));
                    dateandtime.set(Calendar.MONTH, c.get(Calendar.MONTH));
                    dateandtime.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH));
                    expTime.setText(new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()));
                }

                @Override
                public void OnCancelButton(Dialog datedialog) {
                    // TODO Auto-generated method stub
                    datedialog.dismiss();
                }
            });
            dp.show();

            break;
        case R.id.btn_send:
            new postBuyingReqList().execute();

            break;
        case R.id.iv_img:
            showCustomeAlert2(BuyingreqActivity.this, "Yehki", "From Camera", "From Gallery");

            break;

        }

    }

    @SuppressWarnings("deprecation")
    private void showCustomeAlert2(Context context, String title, String rightButton, String leftButton) {
        final Dialog dialog = new Dialog(BuyingreqActivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        dialog.setContentView(R.layout.popup_alert);
        dialog.setCancelable(false);
        final ImageView btn_lft = (ImageView) dialog.findViewById(R.id.iv_left);
        final ImageView btn_rgt = (ImageView) dialog.findViewById(R.id.iv_right);
        final Button cancel = (Button) dialog.findViewById(R.id.btn_cancle);

        final TextView btn_left = (TextView) dialog.findViewById(R.id.btnLeft);
        final TextView btn_right = (TextView) dialog.findViewById(R.id.btnRight);

        btn_left.setText(leftButton);
        btn_right.setText(rightButton);
        cancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        btn_rgt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    System.out.println("=========== perform click ==============");
                    String mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();

                    fileName = "user_" + Pref.getValue(BuyingreqActivity.this, Const.PREF_USER_ID, 0) + "_" + System.currentTimeMillis() + ".png";
                    imageUri = Uri.fromFile(new File(Const.DIR_USER + "/" + fileName));

                    System.out.println(" PATH ::: " + imageUri);

                    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                    startActivityForResult(cameraIntent, CAMERA_CAPTURE);

                } catch (ActivityNotFoundException anfe) {
                    String errorMessage = "Whoops - your device doesn't support capturing images!";

                }

                dialog.dismiss();
            }
        });
        btn_lft.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                // call android default gallery
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                // ******** code for crop image
                intent.putExtra("crop", "true");
                intent.putExtra("aspectX", 0);
                intent.putExtra("aspectY", 0);
                intent.putExtra("outputX", 200);
                intent.putExtra("outputY", 200);

                try {

                    intent.putExtra("return-data", true);
                    startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);

                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    void InitializeView() {
        iv_fav_menu = (ImageView) findViewById(R.id.iv_fav_menu);
        viewReq = (Button) findViewById(R.id.btn_view);
        postReq = (Button) findViewById(R.id.btn_post);
        scr_post = (ScrollView) findViewById(R.id.scr_post);
        scr_view = (RelativeLayout) findViewById(R.id.scr_view);
        quote_view = (RelativeLayout) findViewById(R.id.quote_view);
        quoteList = (ListView) findViewById(R.id.quote_list);

        lv = (ListView) findViewById(R.id.req_list);
        rl_botm = (RelativeLayout) findViewById(R.id.rl_botm);
        header = (Header) findViewById(R.id.headerBuying);
        header.title.setText("Post Buying Request");
        proImg = (ImageView) findViewById(R.id.iv_img);
        productName = (EditText) findViewById(R.id.et_pro_name);
        productCategory = (TextView) findViewById(R.id.tv_pro_cat);
        expTime = (TextView) findViewById(R.id.tv_pro_exp_tym);
        productDesc = (EditText) findViewById(R.id.et_pro_desc);
        estOrderQty = (TextView) findViewById(R.id.et_est_qty);
        send = (Button) findViewById(R.id.btn_send);

    }

    /*
     * getting buying request list...!!!
     */
    private class GetBuyingReqList extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Showing progress dialog
            pDialog = new ProgressDialog(BuyingreqActivity.this);
            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);

            pDialog.show();

        }

        @Override
        protected Void doInBackground(Void... arg0) {

            String query = "?customer_id=" + Pref.getValue(BuyingreqActivity.this, Const.PREF_CUSTOMER_ID, "");
            query = query.replace(" ", "%20");
            viewURL = Const.API_BUYING_REQUEST_LIST + query;
            BackendAPIService sh = new BackendAPIService();

            System.out.println(":::::::::::::::::::ADDRESS URL:::::::::::::::::" + viewURL);
            // Making a request to url and getting response
            String jsonStr = sh.makeServiceCall(viewURL, BackendAPIService.GET);

            Log.d("Response: ", "> " + jsonStr);
            try {
                if (jsonStr != null) {

                    jsonObj = new JSONObject(jsonStr);

                    if (jsonObj.has(Const.TAG_BUYING_REQUEST)) {
                        System.out.println("::::::::::::::::true::::::::::::::::" + jsonObj.has(Const.TAG_ADDRESS_LIST));
                        requestes = jsonObj.getJSONArray(Const.TAG_BUYING_REQUEST);

                        if (requestes != null && requestes.length() != 0) {
                            // looping through All Contacts

                            System.out.println(":::::::::::FLAG IN SUB:::::::::::" + flag);
                            for (int i = 0; i < requestes.length(); i++) {
                                JSONObject c = requestes.getJSONObject(i);

                                buyer_request_id = c.getString(Const.TAG_BUYING_REQUEST_ID);
                                System.out.println(":::::::::::::::MY buying request:::::::::::::" + buyer_request_id);
                                String subject = c.getString(Const.TAG_PRODUCT_NAME);
                                String date_modified = c.getString(Const.TAG_DATE_MODIFIED);
                                String expired_date = c.getString(Const.TAG_EXPIRY_DATE);
                                String quote_count = c.getString(Const.TAG_QUOTE_COUNT);
                                String buying_request_status = c.getString(Const.TAG_BUYING_REQUEST_STATUS);

                                HashMap<String, String> request = new HashMap<String, String>();

                                request.put(Const.TAG_BUYING_REQUEST_ID, buyer_request_id);
                                request.put(Const.TAG_PRODUCT_NAME, subject);
                                request.put(Const.TAG_DATE_MODIFIED, date_modified);
                                request.put(Const.TAG_EXPIRY_DATE, expired_date);
                                request.put(Const.TAG_QUOTE_COUNT, quote_count);
                                request.put(Const.TAG_BUYING_REQUEST_STATUS, buying_request_status);
                                reqList.add(request);
                                System.out.println("::::::::::::::::Is filled:::::::::::" + reqList.size());

                            }
                        }
                    }

                } else {
                    Log.e("ServiceHandler", "Couldn't get any data from the url");
                }

            } catch (JSONException e) {
                e.printStackTrace();
                System.out.println("::::::::::::::::::got an error::::::::::::");
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            // Dismiss the progress dialog
            if (pDialog.isShowing())
                pDialog.dismiss();
            /**
             * Updating parsed JSON data into ListView
             * 
             * */

            buyingRequestContent = new BuyingRequestAdapter(BuyingreqActivity.this, reqList);

            lv.setAdapter(buyingRequestContent);

        }

    }

    public void callGetQuoteListAsyncTask() {
        new GetBuyingReqList().execute();
    }

    /*
     * getting qoute List...!!!
     */
    public class GetQuoteList extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Showing progress dialog
            pDialog = new ProgressDialog(BuyingreqActivity.this);
            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);
            scr_post.setVisibility(View.GONE);
            scr_view.setVisibility(View.GONE);
            quote_view.setVisibility(View.VISIBLE);
            pDialog.show();

        }

        @Override
        protected Void doInBackground(Void... arg0) {

            String query = "?customer_id=" + Pref.getValue(BuyingreqActivity.this, Const.PREF_CUSTOMER_ID, "") + "&buyer_request_id=" + buyer_request_id;
            query = query.replace(" ", "%20");
            viewURL = Const.API_QUOTE_RECIEVED + query;
            BackendAPIService sh = new BackendAPIService();

            System.out.println(":::::::::::::::::::ADDRESS URL:::::::::::::::::" + viewURL);
            // Making a request to url and getting response
            String jsonStr = sh.makeServiceCall(viewURL, BackendAPIService.GET);

            Log.d("Response: ", "> " + jsonStr);
            try {
                if (jsonStr != null) {

                    jsonObj = new JSONObject(jsonStr);

                    if (jsonObj.has(Const.TAG_BUYING_REQUEST)) {
                        System.out.println("::::::::::::::::true::::::::::::::::" + jsonObj.has(Const.TAG_ADDRESS_LIST));
                        requestes = jsonObj.getJSONArray(Const.TAG_BUYING_REQUEST);

                        if (requestes != null && requestes.length() != 0) {
                            // looping through All Contacts

                            System.out.println(":::::::::::FLAG IN SUB:::::::::::" + flag);
                            for (int i = 0; i < requestes.length(); i++) {
                                JSONObject c = requestes.getJSONObject(i);

                                String buyerID = c.getString(Const.TAG_BUYING_REQUEST_ID);
                                System.out.println(":::::::::::::::MY buying request:::::::::::::" + buyerID);
                                String product_name = c.getString(Const.TAG_PRODUCT_NAME);
                                String quote_id = c.getString(Const.TAG_QUOTE_ID);
                                String supplier_name = c.getString(Const.TAG_SUPPLIER_NAME);
                                String status = c.getString(Const.TAG_STATUS);

                                HashMap<String, String> quote = new HashMap<String, String>();

                                quote.put(Const.TAG_BUYING_REQUEST_ID, buyerID);
                                quote.put(Const.TAG_PRODUCT_NAME, product_name);
                                quote.put(Const.TAG_QUOTE_ID, quote_id);
                                quote.put(Const.TAG_EXPIRY_DATE, supplier_name);
                                quote.put(Const.TAG_QUOTE_COUNT, status);
                                queList.add(quote);
                                System.out.println(":::::::::::::Buyer request ID:" + buyerID);
                            }
                        }
                    }

                } else {
                    Log.e("ServiceHandler", "Couldn't get any data from the url");
                }

            } catch (JSONException e) {
                e.printStackTrace();
                System.out.println("::::::::::::::::::got an error::::::::::::");
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            // Dismiss the progress dialog
            if (pDialog.isShowing())
                pDialog.dismiss();
            /**
             * Updating parsed JSON data into ListView
             * 
             * */

            quoteAdapter = new QuoteAdapter(BuyingreqActivity.this, reqList);

            quoteList.setAdapter(quoteAdapter);

        }

    }

    // ============================
    /*
     * post Buying Request api()...!!!
     */
    private class postBuyingReqList extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Showing progress dialog
            pDialog = new ProgressDialog(BuyingreqActivity.this);

            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);
            pDialog.show();

        }

        @Override
        protected Void doInBackground(Void... arg0) {
            postURL = Const.API_BUYING_REQUEST + "?customer_id=" + Pref.getValue(BuyingreqActivity.this, Const.PREF_CUSTOMER_ID, "") + "&product_name=" + productName.getText().toString().trim()
                    + "&category_id=1&expire_time=" + expTime.getText().toString() + "&detail_desc=" + productDesc.getText().toString().trim() + "&esti_ordr_qty="
                    + estOrderQty.getText().toString().trim() + "&esti_ordr_qty_unit=1&filename=abc.jpg&image=abc.png";
            // Creating service handler class instance
            postURL = postURL.replace(" ", "%20");
            BackendAPIService sh = new BackendAPIService();

            System.out.println(":::::::::::::::::::post buying request URL:::::::::::::::::" + postURL);
            // Making a request to url and getting response
            String jsonStr = sh.makeServiceCall(postURL, BackendAPIService.POST);

            Log.d("Response: ", "> " + jsonStr);
            try {
                if (jsonStr != null) {

                    jsonObj = new JSONObject(jsonStr);
                    if (jsonObj.get("status").equals("success")) {
                        flag = 0;
                    }

                } else {
                    Log.e("ServiceHandler", "Couldn't get any data from the url");
                }

            } catch (JSONException e) {
                e.printStackTrace();
                System.out.println("::::::::::::::::::got an error::::::::::::");
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            Intent i;
            // Dismiss the progress dialog
            if (pDialog.isShowing())
                pDialog.dismiss();
            if (flag == 0) {
                Utils.showCustomeAlertValidation(BuyingreqActivity.this, "Request Posted", "Yehki", "OK");
                clearViews();

            } else {
                Toast.makeText(BuyingreqActivity.this, "Buying Request has not been posted", 0).show();
            }
            /**
             * Updating parsed JSON data into ListView
             * 
             * */

        }

    }

    void clearViews() {
        productName.setText("");
        productDesc.setText("");
        estOrderQty.setText("");
        expTime.setText("Expiration Time");
        proImg.setImageResource(R.drawable.noimage);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == CAMERA_CAPTURE) { // for camera
            try {
                System.out.println("============= FILENAME :: " + fileName);
                if (new File(Const.DIR_USER + "/" + fileName).exists()) {
                    performCrop();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (requestCode == 2) { // for crop image
            try {
                if (data != null) {
                    Bundle extras = data.getExtras();
                    Bitmap thePic = extras.getParcelable("data");

                    Utils.createDirectoryAndSaveFile(thePic, Const.DIR_USER + "/" + fileName);

                    // pro_pic.setImageBitmap(thePic);
                    @SuppressWarnings("deprecation")
                    Drawable dra = (Drawable) new BitmapDrawable(thePic);
                    proImg.setImageDrawable(dra);
                    proImg.setScaleType(ScaleType.FIT_XY);

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (requestCode == PICK_FROM_GALLERY && resultCode == RESULT_OK) {

            if (data != null) {
                /*
                 * fileName = Const.DIR_USER + "/" + "user_" +
                 * Pref.getValue(ProfileActivity.this, Const.PREF_USER_ID, 0) +
                 * "_" + System.currentTimeMillis() + ".png";
                 */
                fileName = "user_" + Pref.getValue(BuyingreqActivity.this, Const.PREF_USER_ID, 0) + "_" + System.currentTimeMillis() + ".png";
                Bundle extras2 = data.getExtras();
                Bitmap photo = extras2.getParcelable("data");

                Utils.createDirectoryAndSaveFile(photo, Const.DIR_USER + "/" + fileName);
                ImageView picView = (ImageView) findViewById(R.id.iv_img);
                picView.setImageBitmap(photo);

            }

        }
    }

    private void performCrop() {
        try {

            System.out.println("============= AFTER FILENAME :: " + fileName);

            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            imageUri = Uri.fromFile(new File(Const.DIR_USER + "/" + fileName));
            cropIntent.setDataAndType(imageUri, "image/*");
            cropIntent.putExtra("crop", "true");
            cropIntent.putExtra("aspectX", 1);
            cropIntent.putExtra("aspectY", 1);
            cropIntent.putExtra("outputX", 200);// 256
            cropIntent.putExtra("outputY", 200);

            cropIntent.putExtra("return-data", true);
            startActivityForResult(cropIntent, 2);
        }

        catch (ActivityNotFoundException anfe) {

            String errorMessage = "Whoops - your device doesn't support the crop action!";
            Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
            toast.show();
        }
    }

}
**活动**
**活动**
导入java.io.File;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.Calendar;
导入java.util.HashMap;
导入java.util.Locale;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.app.Dialog;
导入android.app.ProgressDialog;
导入android.content.ActivityNotFoundException;
导入android.content.Context;
导入android.content.Intent;
导入android.graphics.Bitmap;
导入android.graphics.drawable.BitmapDrawable;
导入android.graphics.drawable.ColorDrawable;
导入android.graphics.drawable.drawable;
导入android.net.Uri;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.os.Environment;
导入android.provider.MediaStore;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.view.ViewGroup.LayoutParams;
导入android.view.Window;
导入android.view.WindowManager;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageView;
导入android.widget.ImageView.ScaleType;
导入android.widget.ListView;
导入android.widget.RelativeLayout;
导入android.widget.ScrollView;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.epe.yehki.adapter.BuyingRequestAdapter;
导入com.epe.yehki.adapter.QuoteAdapter;
导入com.epe.yehki.backend.BackendAPIService;
导入com.epe.yehki.uc.Header;
导入com.epe.yehki.util.Const;
导入com.epe.yehki.util.Pref;
导入com.epe.yehki.util.Utils;
导入com.example.yehki.R;
公共类BuyingreqActivity扩展了活动实现OnClickListener{
按钮viewReq,postReq;
EditText产品名称;
文本视图产品类别;
文本视图扩展时间;
TextView产品描述;
TextView Estorqty;
图像视图proImg;
按钮发送;
ImageView iv_fav_菜单;
私有int标志=1;
滚动查看scr_post;
相对年轻的scr_视图;
相对引用视图;
私人对话;
字符串viewURL,postrl;
JSONObject jsonObj;
字符串quote_id,buyerID;
JSONArray请求=null;
JSONArray引号=null;
ArrayList请求列表;
ArrayList任务列表;
私有BuyingRequestAdapter buyingRequestContent;
私人Quotedapter Quotedapter;
相对性;
ListView lv;
收割台;
日历日期和时间;
私人静态最终整型从摄像机拾取=100;
私有静态最终整型从库中选取=200;
私有Uri-picUri;
内拉,洛;
最终int摄像机_捕捉=1;
私有静态字符串文件名;
意图为空;
列表视图引用列表;
私有字符串路径;
私有Uri-imageUri;
字符串买方请求id、请求id;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏);
setContentView(R.layout.activity\u busing\u request);
初始化视图();
productCategory.setOnClickListener(此);
send.setOnClickListener(this);
setOnClickListener(这个);
proImg.setOnClickListener(此);
dateandtime=Calendar.getInstance(Locale.US);
header.back.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
完成();
}
});
reqList=新的ArrayList();
queList=newarraylist();
viewReq.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
flag=2;
reqList.clear();
iv_fav_菜单。setBackgroundResource(R.drawable.tab_两个fav);
callGetQuoteListAsyncTask();
scr_view.setVisibility(视图可见);
quote_view.setVisibility(view.GONE);
rl_botm.setVisibility(视图已消失);
scr_post.setVisibility(视图已消失);
}
});
lv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//TODO自动生成的方法存根
in=新意图(getApplicationContext(),BuyingRequestDetailActivity.class);
//正在从标记获取ProductId。。。
reqID=reqList.get(位置).get(常量标签\u购买\u请求\u ID);
System.out.println(“:::::;;Resest DETIALS活动的意图==========================”+reqID);
in.putExtra(Const.TAG\u BUYING\u REQUEST\u ID,requid);
in.putExtra(Const.TAG_QUOTE_ID,QUOTE_ID);
System.out.println(“::::买方Id和请求Id:::;“+reqID+”===>“+quote\u Id”);
星触觉(in);
}
});
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
in=新意图(getApplicationContext(),QuoteDetailActivity.class);
//正在从标记获取ProductId。。。
REQUID=queList.get(位置).g
package com.epe.yehki.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.epe.yehki.ui.BuyingreqActivity;
import com.epe.yehki.ui.BuyingreqActivity.GetQuoteList;
import com.epe.yehki.util.Const;
import com.example.yehki.R;

public class BuyingRequestAdapter extends BaseAdapter {
    public ArrayList<HashMap<String, String>> BuyingRequestArray;
    private Context mContext;

    public BuyingRequestAdapter(Context paramContext, ArrayList<HashMap<String, String>> productList) {
        this.mContext = paramContext;
        this.BuyingRequestArray = productList;

    }

    public int getCount() {
        return this.BuyingRequestArray.size();
    }

    public Object getItem(int paramInt) {
        return Integer.valueOf(paramInt);
    }

    public long getItemId(int paramInt) {
        return paramInt;
    }

    @SuppressWarnings("static-access")
    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
        LayoutInflater localLayoutInflater = (LayoutInflater) this.mContext.getSystemService("layout_inflater");
        Viewholder localViewholder = null;
        if (paramView == null) {
            paramView = localLayoutInflater.inflate(R.layout.raw_buying_req, paramViewGroup, false);
            localViewholder = new Viewholder();
            localViewholder.sub = ((TextView) paramView.findViewById(R.id.sub));
            localViewholder.expDate = ((TextView) paramView.findViewById(R.id.exp_date));
            localViewholder.quote = ((TextView) paramView.findViewById(R.id.quote));
            localViewholder.status = ((TextView) paramView.findViewById(R.id.status));
            localViewholder.lastUpdate = ((TextView) paramView.findViewById(R.id.last_updated));

            paramView.setTag(localViewholder);

        } else {
            localViewholder = new Viewholder();
            localViewholder = (Viewholder) paramView.getTag();
        }

        System.out.println(":::::::::::::::values:::::::::::::::" + BuyingRequestArray.get(paramInt).get(Const.TAG_PRODUCT_NAME));
        localViewholder.sub.setText(BuyingRequestArray.get(paramInt).get(Const.TAG_PRODUCT_NAME));
        localViewholder.expDate.setText(BuyingRequestArray.get(paramInt).get(Const.TAG_EXPIRY_DATE));
        localViewholder.lastUpdate.setText(BuyingRequestArray.get(paramInt).get(Const.TAG_DATE_MODIFIED));
        localViewholder.quote.setText(BuyingRequestArray.get(paramInt).get(Const.TAG_QUOTE_COUNT));
        localViewholder.quote.setTextColor(Color.parseColor("#0000ff"));
        localViewholder.status.setText(BuyingRequestArray.get(paramInt).get(Const.TAG_BUYING_REQUEST_STATUS));

        localViewholder.quote.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                System.out.println("::::::::::::::::::quote clicked...!!");
                /* ((BuyingreqActivity) mContext).new GetQuoteList(); */
                GetQuoteList getQuoteList = ((BuyingreqActivity) mContext).new GetQuoteList();
                getQuoteList.execute();

            }
        });
        return paramView;

    }

    static class Viewholder {
        TextView sub;
        TextView lastUpdate;
        TextView expDate;
        TextView quote;
        TextView status;

    }

}
 Viewholder localViewholder = null;
    if (paramView == null) {
        paramView = localLayoutInflater.inflate(R.layout.raw_buying_req, paramViewGroup, false);
        localViewholder = new Viewholder();
        localViewholder.sub = ((TextView) paramView.findViewById(R.id.sub));
        localViewholder.expDate = ((TextView) paramView.findViewById(R.id.exp_date));
        localViewholder.quote = ((TextView) paramView.findViewById(R.id.quote));
        localViewholder.status = ((TextView) paramView.findViewById(R.id.status));
        localViewholder.lastUpdate = ((TextView) paramView.findViewById(R.id.last_updated));

        paramView.setTag(localViewholder);

    } else {
        localViewholder = new Viewholder();
        localViewholder = (Viewholder) paramView.getTag();
    }
 Viewholder localViewholder ;
   if (paramView == null) {
paramView = localLayoutInflater.inflate(R.layout.raw_buying_req, paramViewGroup, false);
  localViewholder = new Viewholder();
        localViewholder.sub = ((TextView) paramView.findViewById(R.id.sub));
        localViewholder.expDate = ((TextView) paramView.findViewById(R.id.exp_date));
        localViewholder.quote = ((TextView) paramView.findViewById(R.id.quote));
        localViewholder.status = ((TextView) paramView.findViewById(R.id.status));
        localViewholder.lastUpdate = ((TextView) paramView.findViewById(R.id.last_updated));

        paramView.setTag(localViewholder);

    } else {

        localViewholder = (Viewholder) paramView.getTag();
    }
  public Object getItem(int paramInt) {
    return Integer.valueOf(paramInt);
}
  public Object getItem(int paramInt) {
    return BuyingRequestArray.get(paramInt);
}