-3

enter image description here

In the first activity we will show only the date of the purchased and total quantity in a List View. And when user will click on a List Item we will show the items and quantity details in the next activity.

[after clicking on date user will go to next activity where it will show the product name n quantity ]

here is the code for what i have tried

    private ArrayList<parse> milkParss;


    //for Adapter
    private DateAdapter adapter ;
     //Initializing  the listview
        listView_1 = (ListView) findViewById(R.id.listView_1);
        //to get the data from method getData
        adapter = new DateAdapter(this,R.layout.simple_list,);

        listView_1.setAdapter(adapter);

        listView_1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent2 = new Intent(MonthlySummaryActivity.this, UpdateDailySupply.class);
                intent2.putExtra(KEY_DATE, );
                startActivity(intent2);
            }
        });


        //initializing the milkpar
        milkPar = new ArrayList<parse>();

               private void sendRequest() {

        //for processing dialog box

        final ProgressDialog loading = ProgressDialog.show(this, "Fetching Data", "Please wait...", false, false);

        //  JSONArrayRequest req = new JsonObjectRequest(Request.Method.GET, urlJsonArray, null, new Response.Listener<JSONObject>() {
        JsonArrayRequest req = new JsonArrayRequest(Request.Method.GET, urlJsonArray, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                Log.d(TAG, response.toString());
                try {
                    //parsing the value of jsaon array
                    for (int i = 0; i < response.length(); i++) {
                        JSONObject person = (JSONObject) response.get(i);
                        String da = person.getString("date");
                        String pr = person.getString("product");
                        String na = person.getString("Person");
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                    Toast.makeText(MonthlySummaryActivity.this, "ERROR" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }

                },
                   new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(MonthlySummaryActivity.this, "error::" + error.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });
}





public class DateAdapter extends BaseAdapter {

    private List<parse> list = new ArrayList<parse>();
    private Context context ;

    public DateAdapter(List<parse> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       View view = convertView ;
        if (view == null ){
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.simple_list,null);

        }
        return convertView ;
    }
}

[2]

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
sahil kumar
  • 1
  • 1
  • 2

1 Answers1

0

Getting used to android's volley may be confusing at first, but once you get the hang of it, it will be easy. Once you have the data from parsing JSON, you can then pass it to another activity using bundle or extra from Intent.

RequestQueue queue = Volley.newRequestQueue(getActivity());
    StringRequest sr = new StringRequest(Request.Method.POST, myUrl,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    //getting the response
                    try {
                        JSONArray jsonArray = new JSONArray(s);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            String name;
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            name= jsonObject.getString("name");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.wtf("error", e.getMessage());
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {

        }
    }) {
//sending a request
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("id", id);
            return params;
        }
    };
    queue.add(sr);
fmpsagara
  • 485
  • 5
  • 17