为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
Android攻城狮的第二门课(第1季)_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

Android攻城狮的第二门课(第1季)

Smile浅笑 JAVA开发工程师
难度入门
时长 5小时 0分
  • 处理Fragment事务.add() /remove()/ replace()
    查看全部
  • ViewPager实现的功能
    查看全部
    0 采集 收起 来源:认识ViewPager

    2015-07-09

  • inflater.inflate(布局文件,加载layout的父ViewGroup,false->不返回父ViewGroup)
    查看全部
  • Fragment和Activity的通信 1. Fragment通过getActivity()来获得它所在的Activity 3. Activity->Fragment: 在Activity中创建Bundle数据包,并调用Fragment的setArguments(Bundle bundle)方法将数据包传递进去;在Fragment中调用getArguments()获取数据包 Acitivty中: MyFragment5 myFragment5 = new MyFragment5(); Bundle bundle = new Bundle(); bundle.putString("name", message); //"name"为对应的key,message是传递的string myFragment5.setArguments(bundle); //发送数据给myFragment5 对应的MyFragment5中: Bundle bundle = getArguments(); //获取bundle数据包 String message = bundle.getString("name")+""; //把“name”key对应的value拿出来 mTV.setText(message); 4. Fragment->Activity: 需要在Fragment中定义一个内部回调接口,再让包含它的Activity实现该回调接口。这样Fragment中可调用该回调方法将数据传递给Activity。 (1)Fragment中定义一个内部回调接口 public interface MyListener { public void response(String reponseString); } (2)Activity中实现该方法 MainActivity4 implements MyListener { public void response(String reponseString) { mTV.setText(reponseString); } } (3)Fragment中回调MainActivity4中的该方法 ((MyListener) getActivity()).response(responseString);
    查看全部
  • Fragment生命周期 1. 启动Fragment onAttach()->onCreate()->onCreateView()->onActivityCreated()->onStart()->onResume() 2. 屏幕锁屏 onPause()->onStop() 3. 屏幕解锁 onStart()->onResume() 4. 切换其他Fragment 前一个Fragment: onPause()->onStop()->onDestoryView()->onDestory()->onDetach() 后一个Fragment: onAttach()->onCreate()->onCreateView()->onActivityCreated()->onStart()->onResume() 5. 回到桌面 onPause()->onStop() 6. 回到应用 onStart()->onResume() 7. 退出Fragment onPause()->onStop()->onDestoryView()->onDestory()->onDetach() 当Fragment被添加到Activity中时,调用该onAttach方法,并且只调用一次 创建Fragment时调用onCreate,并且只调用一次 次创建Fragment时,都会调用该onCreateView方法绘制View组件 onDestroyView:销毁Fragment所包含的view组件 貌似 最多有三个活动的Fragment
    查看全部
  • Fragment生命周期
    查看全部
  • 动态加载源代码 fragment.xml 在Button中加一个android:text="改变" <Button android:text="改变" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" />
    查看全部
  • 动态加载源代码 MyFragment2.java 右键MyFragment-Copy-Paste-改名为MyFragment2 (内容就改了一个字:静-〉动) package com.imooc.android_fragment; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class MyFragment2 extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { /* * layout布局文件如何转换成View对象 * 参数1:resource:Frament需要加载的布局文件 * 参数2:root:加载layout的父ViewGroup * 参数3:attactToRoot:若为false,不返回ViewGroup */ View view=inflater.inflate(R.layout.fragment, container, false); TextView text=(TextView) view.findViewById(R.id.text); text.setTag("动态加载"); return view; } }
    查看全部
  • 动态加载源代码 MainActivity.java变化 case R.id.second: //1:新建对象 MyFragment2 fragment2=new MyFragment2(); //2:获取管理者 FragmentManager fragmentManager=getFragmentManager(); //3:开启事物 FragmentTransaction beginTransaction=fragmentManager.beginTransaction(); /* * 参数1:Fragment将要加载到的布局文件 * 参数2:要被加载的Fragment对象 */ beginTransaction.add(R.id.frame, fragment2); //beginTransaction.remove(arg0); //beginTransaction.replace(arg0, arg1); //4:回退 beginTransaction.addToBackStack(null); //5:提交 beginTransaction.commit(); break;
    查看全部
  • 静态加载源代码 fragment.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" /> </LinearLayout>
    查看全部
  • 静态加载源代码 MyFragment.java package com.imooc.android_fragment; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class MyFragment extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { /* * layout布局文件如何转换成View对象 * 参数1:resource:Frament需要加载的布局文件 * 参数2:root:加载layout的父ViewGroup * 参数3:attactToRoot:若为false,不返回ViewGroup */ View view=inflater.inflate(R.layout.fragment, container, false); TextView text=(TextView) view.findViewById(R.id.text); text.setTag("静态加载"); return view; } }
    查看全部
  • 静态加载源代码 main2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:id="@+id/fragment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:name="com.imooc.android_fragment.MyFragment" /> </LinearLayout>
    查看全部
  • 静态加载源代码 main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RadioGroup android:id="@+id/radiogroup" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/first" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="静态加载" /> <RadioButton android:id="@+id/second" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="动态加载" /> <RadioButton android:id="@+id/thrid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="生命周期" /> <RadioButton android:id="@+id/fourth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="传值通信" /> </RadioGroup> </LinearLayout>
    查看全部
  • 静态加载源代码 MainActivity2.java package com.imooc.android_fragment; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class MainActivity2 extends Activity{ private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main2); Button button=(Button) findViewById(R.id.button); tv=(TextView) findViewById(R.id.text); button.setText("改变"); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub tv.setText("TextView 改变了"); } }); } }
    查看全部
  • 静态加载源代码 MainActivity.java package com.imooc.android_fragment; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{ //OnCheckedChangeListener有两种,这里用的是Group,不是Button private RadioGroup group; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); group=(RadioGroup) findViewById(R.id.radiogroup); group.setOnCheckedChangeListener(this); } @Override public void onCheckedChanged(RadioGroup group, int checkId) { switch (checkId) { case R.id.first: //Intent:准备跳转 //startActivity(intent);执行跳转 Intent intent=new Intent(this,MainActivity2.class); startActivity(intent); break; case R.id.second: break; case R.id.thrid: break; case R.id.fourth: break; default: break; } } }
    查看全部

举报

0/150
提交
取消
课程须知
本课程是Android开发课程进阶部分的第1季,将讲解各种高级控件的使用,对于不熟悉Android开发的童鞋来说会有一定的难度,所以,建议在学习本门课程之前: 1、熟练掌握Java基础语法和面向对象编程 2、熟悉Android开发环境 3、熟练使用Button、ImageView等基础控件
老师告诉你能学到什么?
1、Android高级控件的应用场景 2、Android高级控件的使用方法 3、熟悉Android常用高级控件
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!