我想使用Adapter中存在的片段形式的数据。我使用setArguments()从Adapter发送数据,使用getArguments()接收数据。
但是当我调试它时,我在getArguments上得到了一个nullpointerException。
这就是我发送和接收数据的方式。
在Adapter中,发送数据。
ReversalFragment f1 = new ReversalFragment();
Bundle bundle = new Bundle();
String transId = item.getTxId();
bundle.putString("tId", t
我有以下几点(为了避免检查片段是新创建的还是刚刚重新创建的)
@Override public void onActivityCreated(Bundle args) {
super.onActivityCreated(args);
if (this.getArguments() != null) args = this.getArguments();
// rest of fragment loading goes here
}
我有一个具有以下方法的详细片段:
> @Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (getArguments().containsKey(ARG_ITEM_ID))
{
final Activity activity = this.getActivity();
final CollapsingToolbarLay
我让button click listener在其点击片段被替换,并在下一个片段上传递参数。代码:-
Fragment fragment = new CustomList();
Bundle args = new Bundle();
args.putString("fragment", "Custom");
args.putSerializable("productBean", productBean);
fragment.setArguments(
这是我将参数设置到包中的通用Dialog片段类
public class GeneralDialogFragment extends BaseDialogFragment<GeneralDialogFragment.OnDialogFragmentClickListener> {
public interface OnDialogFragmentClickListener {
public void onClicked(GeneralDialogFragment dialogFragment);
public void onCancel
我需要将int值从一个活动片段传递到另一个片段。然后,这些数据将被设置为一个开关情况,这将决定哪个android布局文件将附加到片段中。
这是来自基本活动的代码和设置要传递的值的片段上的代码:
Fragment fragment = new otherFragment();
Bundle bundle = new Bundle();
bundle.putInt(key, value);
fragment.setArguments(bundle);
顺便说一句,我还试图将上面的代码放在片段的onCreate和onCreateView方法上,但是输出仍然相同。然后,在设置了片段和包之后,我切换到另
实际上,我正在将包从我的基适配器发送到新的片段。如何将捆绑包从适配器发送到帧。下面是我的适配器代码:
textViewItemName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ExpandableCategoryList fragment = new ExpandableCategoryList();
Bundle bundle = new Bun
我的类应该向DialogFragment传递一个参数,但是我的应用程序在NullPointerException的onCreate方法(对话框类)中崩溃了。代码的对话框片段类部分:
public class ConfirmDialog extends DialogFragment {
public ConfirmDialog() {}
ConfirmDialog newInstance(String f) {
ConfirmDialog d = new ConfirmDialog();
Bundle args = new Bundle();
args.putSt
我正在做一个布局,类似于Google play的布局,我使用的是一个需要片段的ViewPager。我现在有点困惑了,因为一些站点说片段需要一个空的构造函数,但developer.android.com上的示例并不包含构造函数。代码如下所示:
public static class DemoObjectFragment extends Fragment {
public static final String ARG_OBJECT = "object";
@Override
public View onCreateView(LayoutInflater
我有两个fragments,我们称之为A& B。A是ListFrag,B是用户输入的表单。下面的粗略说明显示了用户交互。
Fragment A
<ListView>
Item1
Item2 <--link to fragment B
Item3
用户单击Item2并看到
Fragment B
<TextView> - <EditText>
<TextView> - <EditText>
<TextView> - <EditText>
<save button>
用户填写表单,单
我使用以下命令在我的活动中创建包
ListFragment fragment = new ListFragment();
Bundle bundle = new Bundle();
bundle.putInt("i", 0);
Log.i("Bundle", String.valueOf(bundle.getInt("i")));
fragment.setArguments(bundle);
然后我在我的代码片段中获取参数
Bundle bun
我启动片段转换:
Fragment fragment = new InstalacionesEncontradasFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("key", this.instalacionesConCategorias);
fragment.setArguments(bundle);
FragmentManager fragmentManager = getFragmentManager();
InstalacionesEncontradasFragment
Fragment