我有一个具有以下方法的详细片段:
> @Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (getArguments().containsKey(ARG_ITEM_ID))
{
final Activity activity = this.getActivity();
final CollapsingToolbarLay
我想将用户ID从主活动转移到片段中。
所以在主要的活动中,我这样做:
Fragment fragment = new Fragment();
final Bundle bundle = new Bundle();
bundle.putString("id_User", id);
Log.i("BUNDLE", bundle.toString());
fragment.setArguments(bundle);
在日志中我可以看到
BUNDLE : Bundle[{id_User=1}]
在片段中,我在onCreate中对其进行了测试
Bundle a
我想使用Adapter中存在的片段形式的数据。我使用setArguments()从Adapter发送数据,使用getArguments()接收数据。
但是当我调试它时,我在getArguments上得到了一个nullpointerException。
这就是我发送和接收数据的方式。
在Adapter中,发送数据。
ReversalFragment f1 = new ReversalFragment();
Bundle bundle = new Bundle();
String transId = item.getTxId();
bundle.putString("tId", t
我试图从activity 1到activity 2的片段中获取包的额外内容,但getargument()总是作为null返回。
//Using this to get string in fragment
String value = getArguments().getString("abc");
//activity1 code that i used to get the extras
Bundle bundle = new Bundle();
bundle.putString("abc", townextra
我试图将一个implements Parcelable对象从一个活动传递到一个片段。我知道如何从一个活动到另一个活动。我只想试试这个。但是当我收到对象时,它总是收到null。我如何解决这个问题?
currentObject是实现Parcelable的类的对象实例。
ContentMainFragment是片段类
活动中的
Fragment fragment = new ContentMainFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("SampleObject", current
My Requirement :
我的MainActivity从其他应用程序接收数据。MainActivity被列为shareable。
现在,我需要将这些数据传递给MainActivity中的一个MainActivity,并更新fragment's textview。
在MainActivity.java :中,我在处理handleSendText方法中接收到的数据(这是一个URL)。
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain"
字符串值,即accountname不传递给片段。
在适配器类中
Dashboard fragobj = new Dashboard();
bundle = new Bundle();
bundle.putString("accountname", accountName);
// set Fragment class Arguments
fragobj.setArguments(bundle);
In片段
lvDashboard = (ListView) view.findViewById(R.id.lvDashboard);
if (getArguments()!= nu
我有一个FragmentStatePagerAdapter,它在下一个片段中显示了当前片段的细节。这是页面适配器
public class CustomerPagerAdapter extends FragmentStatePagerAdapter
{
public SectionsPagerAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Frag
你好,你能帮我实现如何在谷歌地图片段中获得当前位置吗?
我在应用程序中使用NavigationDrawer,并将地图显示为片段。
但我无法找到显示用户当前位置的解决方案。
下面是我的片段的代码:我只包含了几个方法。
public class MapFragment extends Fragment implements OnMapReadyCallback {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArgu
Android Studio 0.8.7
我有以下函数,它在片段中设置一些参数:
public static Fragment newInstance(UUID uuid) {
Log.d(TAG, "newInstance: " + uuid);
Bundle arguments = new Bundle();
arguments.putSerializable(EXTRA_JOB_ID, uuid);
DetailFragment fragment = new DetailFragment();
我有一个使用ViewPager和TabLayout在多个片段之间切换的HostActivity。当我在选项卡之间切换时,Fragments实例确实获得了更新的数据。我还在Fragment实例的onCreateView中看到了更新的数据,但TextView.setText没有更新。当我检查Fragment的可见性时,它总是显示为不可见。如何在切换选项卡时使片段可见,以便使用新数据更新视图?片段/活动生命周期中是否遗漏了什么?我是第一次实现ViewPager,所以知道我是否遗漏了什么会很有帮助。
片段类:
public class StepFragment extends Fragment { @
我有一个主活动,它使用以下代码创建片段
private void launchFragment(int pos)
{
Fragment f = null;
String title = null;
if (pos == 1)
{
title = "Friends";
f = new FriendList();
}
else if (pos == 2)
{
title = "Notes";
f = new NoteList();
}
我在android studio中选择了一个带有"Action bar tabs“的选项卡式活动模板。
然后,我创建了三个片段(One.java、Two.java、Three.java),每个标签对应一个片段。
我有与第二个fragment.The中的游标相关的代码,当我运行应用程序时,第二个片段中的代码没有被执行。
我的问题是,片段(Two.java)将被隐式调用,还是需要通过创建实例来调用(如果是,如何调用?)
MainActivity.java的代码片段
public View onCreateView(LayoutInflater inflater, ViewGroup co