将String数据从活动传递到片段的问题

时间:2017-05-04 07:29:46

标签: java android

我需要将String数据从activity传递给fragment。 我不知道为什么,但是当我尝试在片段中传递数据时,对象束为空。

提前感谢您的帮助!

我告诉你我的代码:

活动:

for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject c = jsonArray.getJSONObject(i);

                   // title_array.add(c.getString("title").toString());
                    url_pdf=c.getString("url_pdf");

                    SixFragment feedBackFragment =new SixFragment();

                        Bundle bundle = new Bundle();
                        bundle.putString("key", url_pdf);
                        // set Fragmentclass Arguments
                        feedBackFragment.setArguments(bundle);



                }

FRAGMENT:

 public class SixFragment  extends android.support.v4.app.Fragment {
String url_pdf="";
    SimpleAdapter adapter;
    ListView list;
    ArrayList<HashMap<String, String>> pdfList;
    HashMap<String, String> pdf;
    String data="";
    String arg="";
    TextView azz;
    String azzzz;
    public SixFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.fragment_six, container, false);

        Bundle bundle = getArguments();
        System.out.println("ARGUMENTS:" + bundle);

        if (bundle != null) {
            arg = bundle.getString("key");
            System.out.println("PDF FETCHHHHHHHHH:"+arg);
        }


        return view;

    }
}

0 个答案:

没有答案