如何从AsyncTask onPostExecute方法传递Fragment类中的变量

时间:2015-12-28 02:48:30

标签: android android-fragments android-asynctask

需要在onPostExecute级内从onCreateViewFragment函数发送值。我在Fragment类中创建了一个newInstance(String value)方法,并从onPostExecute调用此函数。该值出现在newInstance方法中,但在将值发送到onCreateView时,该值为null。

        onPostExcute(String result){
        FragmentClass.newInstance(result);
     }

     public static FragmentClass newInstance(String value){
        Log.i("New Instance",value);//works fine value is printed here
        EmployeeBranch fragment = new EmployeeBranch();
        Bundle args = new Bundle();
        args.putString("key", value);
        fragment.setArguments(args);
        return fragment;
    }
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Bundle args = getArguments();
        String output=getArguments().getString("key","default");
        Log.i("Output",output);//null value
    }
}

0 个答案:

没有答案