欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Fragment-向Activity中添加Fragment,并相互交互

一、activity

10年積累的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有武寧免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

一般書寫代碼時(shí)在oncreate方法中引用initview()、initdata()、initload()進(jìn)行初始化

package com.ping.myfragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MainActivity extends FragmentActivity {//當(dāng)activity中引入fragment時(shí)應(yīng)該繼承--FragmentActivity

 private Myfragment myfragment;
 private TextView activityTV;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  initview();
  initdata();
 }

 private void initdata() {
  FragmentManager fm = getSupportFragmentManager();//獲得fragment的管理對(duì)象
  FragmentTransaction ft = fm.beginTransaction();
  myfragment = new Myfragment();//Fragment每次添加都要重新創(chuàng)建,否則因?yàn)闋顟B(tài)不同會(huì)導(dǎo)致問題  

  ft.add(R.id.container, myfragment);
  ft.commit();
 }

 private void initview() {
  activityTV = (TextView) findViewById(R.id.tv_activity);
  findViewById(R.id.bt_activity).setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    myfragment.settext();
   }
  });
 }

 public void settext() {
  activityTV.setText("activity修改成功");
 }
}

二、fragment

package com.ping.myfragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

public class Myfragment extends Fragment {

 private TextView fragmentTV;

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View inflate = inflater.inflate(R.layout.layout_myfragment, null);
  initview(inflate);
  return inflate;
 }

 private void initview(View inflate) {
  final MainActivity activity = (MainActivity) getActivity();
  fragmentTV = (TextView) inflate.findViewById(R.id.tv_fragment);
  inflate.findViewById(R.id.bt_fragment).setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    activity.settext();
   }
  });
 }

 public void settext() {
  fragmentTV.setText("fragment修改成功");
 }
}

 

三activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" >
    </FrameLayout>

    <TextView
        android:id="@+id/tv_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/container"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="activity中的textview" />

    <Button
        android:id="@+id/bt_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_activity"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="17dp"
        android:text="改變fragment中的textview" />

</RelativeLayout>

四、fragmen.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eeeeee">

    <TextView
        android:id="@+id/tv_fragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="fragment中的textview" />

    <Button
        android:id="@+id/bt_fragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_fragment"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="改變activity中的textview" />

</RelativeLayout>

當(dāng)前文章:Fragment-向Activity中添加Fragment,并相互交互
轉(zhuǎn)載源于:http://www.aaarwkj.com/article28/igeccp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、自適應(yīng)網(wǎng)站虛擬主機(jī)、動(dòng)態(tài)網(wǎng)站、企業(yè)建站外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
日本高清久久一区二区三区| 亚洲性感美女男人的天堂| 国产精品久久久在线视频| 中文字幕三级电影天堂| 亚洲综合色一区二区三区小说| 欧美黄片网站在线观看| 蜜桃网站视频免费观看| 日韩欧美国产精品专区| 国产免费不卡午夜福利在线| 国产一区二区毛多内射| 91成人大片在线观看| 日韩av裸体在线播放| 热热久久这里只有精品| 国产大学生情侣在线视频| 偷拍一区二区三区免费| 白白色最新福利在线视频观看| 亚洲黄色片成年人免费观看| 日韩一区二区高清看片| 日韩视频在线不卡观看| 亚洲av毛片在线免费播放| 精品国产一区亚洲二区| 亚洲人妻av一区二区| 一区二区三区国产不卡| 91薄丝激情在线播放| 一区二区三区四区自拍偷拍视频| 亚洲日本一区二区高清在线| 亚洲黄色成人免费观看| 亚洲av成人在线观看| 午夜视频在线观看日韩| 亚洲综合国产中文字幕| 2023国产精品一区| 国产老熟女高潮精品视频网站免费 | 91久久一区二区秋霞免费| 男女裸体做爰一进一出视频| 伊人久久九九精品综合| 在线播放国产91精品| 日韩av熟女人妻一区二| 91欧美日韩在线观看视频| 日韩有码高清av在线| 欧美日韩一区二区激情在线| 国产成人av在线观看|