How to set values after using model class for global ArrayList?

后端 未结 3 884
迷失自我
迷失自我 2021-01-29 10:59

I\'ve created one model class to store my product name,price and quantity,and then I attach it to another Fragment and try to display it in my TextView

相关标签:
3条回答
  • 2021-01-29 11:20

    First create an application class like this,

    public class Applicationc extends Application{

    public String str;
    
    @Override
    public void onCreate() {
        super.onCreate();
    
        str=null;
    }
    

    }

    create its entry like this in manifest

    then in onPost of Async Task set the value in following way,

    Applicationc app=(Applicationc)getApplicatoncotext(); app.str="data";

    And where you want to retrieve value in following way,

    Applicationc app=(Applicationc)getApplicatoncotext(); String dd=app.str;

    0 讨论(0)
  • 2021-01-29 11:37

    I can't really follow all this code. If I understand you correctly, you are having a problem passing the data around between your Activity, AsyncTask and Fragments. A good architecture here would be to have the Activity keep track of the data. The Fragment can always ask the Activity for the data and the AsyncTask can also call back to the Activity to update the data.

    If this isn't enough information to solve your problem, please show exactly the place where you are having trouble.

    0 讨论(0)
  • 2021-01-29 11:37
    relcart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
    
            _value.setText("1");
            Add_to_cart tf = new Add_to_cart();
    
            tf.setList(productArraylist);
    
            android.support.v4.app.FragmentManager fm = getFragmentManager();
            android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
            ft.replace(R.id.frame_container, tf);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.addToBackStack(null);
            ft.commit();
        }
    });
    

    Add below method in Fragment.

    public void setList(ArrayList<Arr_Model> p_productArraylist) {
           productArraylist = p_productArraylist;
    }
    
    0 讨论(0)
提交回复
热议问题