标签: android-fragmentactivity

无法从片段中投射

我在我的布局中定义了两个片段MainActivity并设置了setContentView.我想从这些片段中调用一些方法,但我不知道如何访问它们.Eclipse说:"无法将表单片段转换为ListFileFrgament".

public class MainActivity extends FragmentActivity {

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

    setContentView(R.layout.activity_main);

    FileListFragment listFragment = (FileListFragment) getFragmentManager().findFragmentById(R.id.list_fragment);  
     // cannot casr here
    PlayerFragment playerFragment = (PlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment); 
     // cannot cast here
    }


}
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-fragmentactivity

8
推荐指数
2
解决办法
7276
查看次数

Eclipse自动创建片段布局,如何禁用它

我不想使用片段和片段布局.这有可能禁用eclipse的那个属性吗?首先,我创建一个类和xml文件,然后我在Android Manifest文件中声明它们对我有用但是如果我可以禁用它需要很长时间,它会更容易.

http://i.hizliresim.com/KgMJvQ.png

eclipse android fragment android-fragments android-fragmentactivity

8
推荐指数
1
解决办法
2万
查看次数

尝试使用FragmentActivity时无法访问ActivityCompatApi23

我正在尝试在我的智能手表上使用ViewPager,但在尝试重建/运行/调试我的应用程序时仍然遇到错误.我正在使用FragmentActivity,这是发生错误的地方.我搜索了stackoverflow和教程网站,看看可能是什么问题,并且很多结果都与build.gradle文件有关.但是我几乎尝试了所有我偶然发现的事情,但错误并没有改变一次.

错误:

Error: Cannot acces ActivityCompatApi23
Run Code Online (Sandbox Code Playgroud)

错误发生在这一行,来自下面的代码段.

public class WearMainActivity extends FragmentActivity {
Run Code Online (Sandbox Code Playgroud)

WearMainActivity.java

package be.ehb.dt.finalwork_lievenluyckx_v001;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

import java.util.List;
import java.util.Vector;

/**
 * Created by Lieven on 14/08/17.
 */

public class WearMainActivity extends FragmentActivity {


    private PagerAdapter pagerAdapter;

    /* (non-Javadoc)
      * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
      */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.viewpager);
        //initialsie the pager
        initialisePaging();
    }

    /**
     * Initialise the fragments to be paged
     */
    private void initialisePaging() {

        List<Fragment> …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-fragmentactivity build.gradle

8
推荐指数
2
解决办法
6035
查看次数

使用ViewPager阻止预加载下一个片段(制表符)

我正在使用Fragments在Android中开发一个应用程序.我有这三个标签:

用户应用截图

我知道这是不可能的,以防止一个片段的每一侧上的负荷(前一个和下一个)尽可能的最小值setOffScreenPageLimit()是1,但它意味着,如果我想显示ProgressDialogonPreExecute一个方法AsyncTask中运行Descargas片段这会导致当我导航到Capturador时,必须加载ProgressDialog吗?如果是,我不知道如何让用户知道我正在下载软件包(这就是Descargas所做的,解析一些XML).

提前致谢 ;)

android android-fragments android-fragmentactivity

7
推荐指数
1
解决办法
5412
查看次数

片段Detatch/Reattach Vs显示/隐藏

我无法找到在没有寻呼机的情况下浏览片段的正确方法,并且在屏幕方向的配置更改期间遇到问题.我在片段上使用Show/Hide来使它们可见并且功能正常但我想知道我是否应该使用Detach/Attach.我也有问题在后台堆栈添加东西,我认为这也是由于使用show/hide.是否更好地使用附加/分离或有一种方法来覆盖后退按钮的作用,使其显示/隐藏最后/当前片段.

行为:我有一个地图片段和一个List片段以及其他一些片段.一切都正确启动,最初工作方向更改.当我导航到列表视图时,它会正确填充,但在方向更改时,列表会重新绘制而不包含数据.地图视图也会重新绘制,并且在我的寻呼机标题指示器后面可见.如果有人可以请我指出正确的方向来解决这个问题,这将是非常棒的.我怀疑这是由我展示和隐藏片段的方式引起的.

这是我创建片段并将其添加到片段管理器的位置.我还展示了我显示/隐藏片段的位置.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_frags);
    mapViewContainer = LayoutInflater.from(this)
            .inflate(R.layout.map, null);

    setupFragments();
    showFragment(0);
}
public void setListData(String name) {
    bName = name;
    showFragment(1);
}
private void setupFragments() {
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    mFragment1 = fm.findFragmentByTag("f1");
    if (mFragment1 == null) {
        mFragment1 = new MenuFragment();
        ft.add(mFragment1, "f1");
        ft.hide(mFragment1);
    }
    mMapFragment = (MapFragment) getSupportFragmentManager()
            .findFragmentByTag(MapFragment.TAG);
    if (mMapFragment == null) {
        mMapFragment = MapFragment.newInstance(0);
        ft.add(R.id.fragment_container, mMapFragment, MapFragment.TAG);
    }
    ft.hide(mMapFragment);

    myListFragment = (ListFrag) …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-fragmentactivity

7
推荐指数
1
解决办法
3493
查看次数

片段和片段活动本质上比活动更快?

片段和片段活动本质上比活动更快?

如果我不需要在片段中加载我的活动,我应该使用FragmentActivities和Fragments over Activities吗?

我要问的原因是因为我多年来一直在使用活动,Facebook SDK以及谷歌地图2.0迫使我使用碎片,我现在想知道它们本质上是否"更好"与否其他实施.

如果这"不具有建设性"或"过于开放",那么答案显然是"不".但如果有一些谷歌开发者文档或博客关于这个确切的主题,那么我想知道它

android android-fragments android-view android-activity android-fragmentactivity

7
推荐指数
1
解决办法
1994
查看次数

使用片段从库中选择图像

我试图使用从fragmentactivity调用的片段从gallery获取图像,但onActivityResult片段类没有被调用.我发现这可能是由于onActivityResultFragmentActivity类的原因而发生的,但是当我检查两个类上的日志时,non不被调用,因此我无法从库中访问所选图像.

我已经尝试了大多数解决方案,但仍然无法弄清楚问题.

我的主要片段活动

public class CreateEvent extends FragmentActivity{

private int CREATE =0;
private int INVITE = 1;
private int FRAGMENT_COUNT = INVITE +1;
private Fragment[] fragment = new Fragment[FRAGMENT_COUNT]; 
private boolean isResumed = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FragmentManager fm = getSupportFragmentManager();
        fragment[CREATE] = fm.findFragmentById(R.id.create);
        fragment[INVITE] = fm.findFragmentById(R.id.invite);
        FragmentTransaction transaction = fm.beginTransaction();
        for(int i = 0 ; i<fragment.length; i++)
        {
            transaction.hide(fragment[i]);
        }
        transaction.commit();
    };
        private void showfragment(int fragmentIndex, boolean addToBackStack)
        {
            FragmentManager fm …
Run Code Online (Sandbox Code Playgroud)

android image-gallery fragment android-fragmentactivity

7
推荐指数
1
解决办法
1万
查看次数

如何在选项卡式活动中的每个选项卡中添加不同的Activtity

我已经创建了选项卡式活动,请帮助我如何在可滑动的TabLayout中的不同选项卡中显示不同的布局.我们如何在每个选项卡中添加不同的活动,例如,当我们在一个布局中添加图像,然后将屏幕更改布局滑动到另一个布局时.

以下是我的代码;

主要活动

package com.example.saeed.salehkhana;

import java.util.Locale;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentPagerAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, …
Run Code Online (Sandbox Code Playgroud)

android android-fragmentactivity android-tablayout

7
推荐指数
2
解决办法
8107
查看次数

如何用另一个DialogFragment替换DialogFragment?

我们通过执行以下操作以编程方式添加一般/正常Fragment:

fragmentTransaction.add(containerViewId, fragmentToAdd, fragmentTag);
Run Code Online (Sandbox Code Playgroud)

我们更换一个Fragment做类似的另一种:

fragmentTransaction.replace(containerViewId, newFragment, tagOfNewFragment);
Run Code Online (Sandbox Code Playgroud)

但是,我们添加一个DialogFragment

dialogFramentInstance.show(fragmentManager, fragmentTag);
Run Code Online (Sandbox Code Playgroud)

现在的问题是,我应该怎么更换这个DialogFragment已经被添加show()的方法?

android android-fragments android-dialogfragment android-fragmentactivity

7
推荐指数
1
解决办法
3017
查看次数

您的活动尚未附加到应用程序实例。在 onCreate 调用之前不能请求 ViewModel

我尝试在固定到其托管活动中的 viewId 的fragmentDialog 上运行测试

  @Test
  public void largeScreenDeviceUsesPopup() {
    final FragmentUtilActivity fragmentActivity = new FragmentUtilActivity();
    fragmentActivity.onCreate(null);

    myDialogFragment = MyDialogFragment.create(FragmentUtilActivity.anchorId);
    myDialogFragment.showNow(fragmentActivity.getSupportFragmentManager(), "");

    assertThat(....)
  }

  private static class FragmentUtilActivity extends FragmentActivity  {

  public static int anchorId = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      LinearLayout view = new LinearLayout(this);
      view.setId(anchorId);

      setContentView(view);
    }
  }
Run Code Online (Sandbox Code Playgroud)

但是我收到这个错误:

Your activity is not yet attached to the Application instance. You can't request ViewModel before onCreate call.
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

android fragment android-activity android-fragmentactivity

7
推荐指数
0
解决办法
6260
查看次数