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
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;
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 Fragment
s. 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.
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;
}