caling fragment method inside adapter but my value going null what should add?

57 Views Asked by At

This is my CartAdapter I called GetCart function in this adapter my function is calling successfully but my orgmst id and userid going null to database.

            quantity.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    new GetUpdateQuantity().execute();
                    TwoFragment fragment = new TwoFragment();
                     fragment.Getcart();
                    if (quantity.length() == 0) {


                    } else {

                        quan = Double.parseDouble(quantity.getText().toString());
                        rate = Double.parseDouble(rate1.getText().toString());
                        total1 = Double.parseDouble(String.valueOf(rate * quan));
                        // convert double to string to get value
                        String show = Double.toString(total1);
                        //show in Textview
                        total.setText(show);

                        Log.d("<<<hcvyd", "" + show);
                    }

                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });


----------

In myfragment i create method to send data to webservice this method i call in GetCart function then this function call inside adapter

MyFragment

'''GetCart Function'''
    public void Getcart(){              
       String gh =  orgmstid;
       String hj =  userid;
           new GetCartItems().execute();
    }
    
    
   
        private class GetCartItems extends AsyncTask<Void, Void, Void> {
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
    
       
            }
    
            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
            @Override
            public Void doInBackground(Void... arg0) {
                HttpHandler sh = new HttpHandler();
    
   
                String jsonStr = sh.makeServiceCall("VIEW_CART", "F", "" + 'N' + "~" + orgmstid + "~" + userid);
               
    
    

                        
1

There are 1 best solutions below

0
Yogesh Bangar On

Code for background CAll

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import android.os.AsyncTask;
import android.util.Log;
public class DownloadFileFromURL extends AsyncTask<String, String, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
    @Override
    protected String doInBackground(String... f_url) {
        try {
            URL url = new URL(f_url[0]);
            URLConnection conection = url.openConnection();
            conection.connect();
            InputStream input = new BufferedInputStream(url.openStream(), 8192);
            byte data[] = new byte[1024];
            String file_string = "";
            while ((count = input.read(data)) != -1) {
                for (int i = 0; i < count; i++) {
                    file_string += (char) data[i];
                }
            }
            input.close();
        } catch (Exception e) {
            Log.e("Error: ", e.getMessage());
        }
        return null;
    }
    protected void onProgressUpdate(String... progress) {
        // pDialog.setProgress(Integer.parseInt(progress[0]));
    }
    @Override
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after the file was downloaded
        // dismissDialog(progress_bar_type);
    }
}

Code for calling

new DownloadFileFromURL().execute("URL");