fragment

How to fix Error inflating class null

大兔子大兔子 提交于 2020-01-11 10:07:42
问题 I am trying to make a scrollable tab but when I set a view in my fragment layout the app starts giving error as Error inflating class null.It was working whenthe view is not added but when I add the view in the layout it gives me error. I added the class also as given here but it is not working .How I can fix this here is my fragment code <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

Click an ImageButton which belongs to a CardView inside a RecyclerView

百般思念 提交于 2020-01-11 06:04:56
问题 SOLVED I've fixed it mixing your answers, so I've decided to write down on here. The key has been the ViewHolder constructor: I have deleted the setOnClickListener() and the onClick() methods and I´ve defined this inner class in my ObjectAdapter.java . public static class ViewHolder extends RecyclerView.ViewHolder{ public ViewHolder(View itemView) { super(itemView); card_first_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int position =

Android Jetpack基础——Navigation

試著忘記壹切 提交于 2020-01-11 05:44:10
实现效果如图 Navigation:有三个主要的部分: Navigation graph:也就是Navigatation的xml文件,包含所有的需要跳转的目标 NavHost:一个容器,用于显示 NavController:控制跳转流程 具体实现 新建两个Fragment,HomeFragment和DetailFragment。 在Activity xml中为Fragment添加NavHost容器。 < ? xml version = "1.0" encoding = "utf-8" ? > < androidx . constraintlayout . widget . ConstraintLayout xmlns : android = "http://schemas.android.com/apk/res/android" xmlns : app = "http://schemas.android.com/apk/res-auto" xmlns : tools = "http://schemas.android.com/tools" android : layout_width = "match_parent" android : layout_height = "match_parent" tools : context = ".MainActivity" > <

ActionBarSherlock, ViewPager, TabsAdapter nested Tab Fragments

感情迁移 提交于 2020-01-11 01:08:09
问题 I implemented a ActionBarSherlock with a ViewPager and a TabsAdapter. It works well but now I tried to "push" from a Framework Loaded in "Tab 1" another Fragment. The behavior should be like: I've 3 Tabs in my Application, When launching I see the first Tab where a Fragment with a Button is in it Pressing the Button on the First Tab, the Fragment on the First Tab should be replaced and another Fragment should be displayed I tried to implement this, but I've a black Fragment when Replacing.

Android学习笔记系列五 —— Fragments板块

岁酱吖の 提交于 2020-01-10 11:00:31
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Fragments Fragment必须总是被嵌入到一个activity之中,并且fragment的生命周期直接受其宿主activity的生命周期的影响。例如,一旦activity被暂停,它里面所有的fragment也被暂停,一旦activity被销毁,它里面所有的fragment也被销毁。然而,当activity正在运行时(处于resumed的生命周期状态),你可以单独的操控每个fragment,比如添加或者删除。当你执行这样一项事务时,可以将它添加到后台的一个栈中,这个栈由activity管理着——activity里面的每个后台栈内容实体是fragment发生过的一条事务记录。这个后台栈允许用户通过按BACK键回退一项fragment事务(往后导航)。 当你添加一个fragment作为某个activity布局的一部分时,它就存在于这个activity视图体系内部的ViewGroup之中,并且定义了它自己的视图布局。你可以通过在activity布局文件中声明fragment,用<fragment>元素把fragment插入到activity的布局中,或者是用应用程序源码将它添加到一个存在的ViewGroup中。然而,fragment并不是一个定要作为activity布局的一部分

Iterating in a fragment

和自甴很熟 提交于 2020-01-07 15:40:09
问题 How would I be able to iterate in a fragment? For example I have been doing like this without iterating since I could not figure out the syntax to only change the last part of the ids: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment1,container, false); iv_main_gongcast0 = (ImageView) rootView.findViewById(R.id.iv_main_gongcast0); iv_main_gongcast1 = (ImageView) rootView.findViewById(R.id.iv

Iterating in a fragment

放肆的年华 提交于 2020-01-07 15:38:31
问题 How would I be able to iterate in a fragment? For example I have been doing like this without iterating since I could not figure out the syntax to only change the last part of the ids: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment1,container, false); iv_main_gongcast0 = (ImageView) rootView.findViewById(R.id.iv_main_gongcast0); iv_main_gongcast1 = (ImageView) rootView.findViewById(R.id.iv

教育系统APP(三)

守給你的承諾、 提交于 2020-01-07 15:36:35
挑战任务回顾教育系统APP(二)以及教育系统APP(三) 检验登录和注册模块。请修改MainActivity和LoginActivity,欢迎界面调转入主界面后,自动跳转入登录界面,登录成功后,返回主界面,在主界面的Hello World位置显示:用户名 “登录成功”。 解决方法 解决任务看看一下AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.gdmec.android.boxuegu"> <!--原为android:theme="@style/AppTheme"--> <!--去除ActionBar标题栏--> <!--添加应用图标,app_icon--> <application android:allowBackup="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="

Android Viewpager+Fragment取消预加载及Fragment方法的学习

倾然丶 夕夏残阳落幕 提交于 2020-01-07 05:00:19
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1.在使用ViewPager嵌套Fragment的时候,由于VIewPager的几个Adapter的设置来说,都会有一定的预加载。通过设置s etOffscreenPageLimit(int number ) 来设置预加载的熟练,在V4包中,默认的预加载是1,即使你设置为0,也是不起作用的,设置的只能是大于1才会有效果的。我们需要通过更改V4包中的默认属性才可以。 更改过的V4 包下载地址,应该也可以,我没试过。 2.限制预加载,会出现滑动过程中卡顿现象。其实Fragment中防止预加载主要是防止数据的预加载,Fragment中的VIew预加载是有好处的,我们可以通过Fragment中的一个方法来达到预加载View 但是不加载数据,在Fragment显示的时候才去加载数据。 直接上我项目中使用到的代码: private boolean isVisable = false; @Override public void setUserVisibleHint(boolean isVisibleToUser) { //判断Fragment中的ListView时候存在,判断该Fragment时候已经正在前台显示 通过这两个判断,就可以知道什么时候去加载数据了 if (getUserVisibleHint() &&

浅析:Android--Fragment的懒加载

纵然是瞬间 提交于 2020-01-07 04:43:55
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我们都知道, fragment 放在 viewPager 里面, viewpager 会帮我们预先加载一个,但是当我们要看 fragment 里面的内容时,我们也许只会去看第一个,不会去看第二个,如果这时候不去实现 fragment 的懒加载的话,就会多余的去加载一些数据,造成用户多消耗流量,所以我们采取懒加载的方式。 所谓懒加载,就是当 fragment 完全可见的时候我们再去加载数据 我们知道,当我们去滑动的时候, fragment 会显示与隐藏,当 fragment 完全显示在我们的眼前时, fragment 会调用一个方法 下面直接上代码 首先,我们定义一个抽象类去继承我们的 fragment, package fragment; import android.support.v4.app.Fragment; /** * Fragment懒加载 */ public abstract class LazyFragment extends Fragment{ protected boolean isVisible; @Override public void setUserVisibleHint(boolean isVisibleToUser) {//frahment从不可见到完全可见的时候,会调用该方法