


下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
【移動應用開發(fā)技術】Adroid中Fragment的簡單使用
下面四個步驟就能創(chuàng)建一個簡單的fragment1.擴展Fragmentclass2.在XML或Java中提供顯示3.覆蓋onCreateView方法4.在activity中使用Fragment如下就是簡單的顯例創(chuàng)建一個FirstActivityFragment.java文件,擴展Fragmentclasspackage
com.example.liang.login;
import
android.content.Context;
import
android.os.Bundle;
import
android.support.v4.app.Fragment;
import
android.support.v4.view.VelocityTrackerCompat;
import
android.view.LayoutInflater;
import
android.view.View;
import
android.view.ViewGroup;
import
android.widget.TextView;
import
android.widget.Toast;
/**
*
Created
by
liang
on
2016/7/15.
*/
public
class
FirstActivityFragment
extends
Fragment
{
public
FirstActivityFragment(){
}
@Override
public
View
onCreateView(LayoutInflater
inflater,
ViewGroup
container,
Bundle
savedInstanceState){
View
v
=
inflater.inflate(R.layout.fragment_first,
container,
false);
TextView
textView
=
(TextView)v.findViewById(R.id.showFirstFragmentInfo);
final
Context
context
=
this.getActivity();
textView.setOnClickListener(new
View.OnClickListener()
{
@Override
public
void
onClick(View
v)
{
Toast
hello;
hello
=
Toast.makeText(context,"hello",Toast.LENGTH_LONG);
hello.show();
}
});
return
v;
}
@Override
public
void
onCreate(
Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
}
}為Fragment創(chuàng)建一個xml
fragment_first.xml<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/showFirstFragmentInfo"
android:text="this
is
a
firstFragment"/>
</LinearLayout>并在一個activityview中使用<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#33FF00">
<fragment
xmlns:android=
"/apk/res/android"
xmlns:tools="/tools"
android:id="@+id/fragment"
android:name="com.example.liang.login.FirstActivityFragment"
tools:layout="@la
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 北京2025年北京服裝學院招聘筆試歷年參考題庫附帶答案詳解
- 二零二五版二手房銷售協(xié)議
- 配送水果合同二零二五年
- 2025商業(yè)大廈租戶裝修管理合同
- 2025合同違約金的計算與處理程序
- 2025中國農業(yè)銀行個人汽車貸款合同
- 2025華能石島灣核電開發(fā)有限公司培訓中心辦公室改造施工合同
- 2025協(xié)商解除勞動合同合同書范本專業(yè)版(合同示范文本)
- 2025《合同法》第所規(guī)定無效合同之情形
- 2025標準版養(yǎng)殖保險合同
- 譚其驤歷史地理十講
- 新版DFMEA基礎知識解析與運用-培訓教材
- 年度IT投資預算表格
- 學習質量評價:SOLO分類理論
- 2023年上海學業(yè)水平考試生命科學試卷含答案
- 中醫(yī)內科學總論-課件
- 免疫學防治(免疫學檢驗課件)
- 消防水泵房操作規(guī)程
- 腹腔雙套管沖洗操作
- 《微型消防站建設標準》
- 中國少年先鋒隊入隊申請書 帶拼音
評論
0/150
提交評論