使用Fragment来处理Andoird app的UI布局的实例分享

2019-12-10 18:59:10王振洲

④FragementDetails.java的代码,这个比较简单,里面有一个设置TextView内容的方法,其布局页面也仅仅是一个TextView

package com.example.fragementexam; 
 
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 FragementDetails extends Fragment { 
 
  @Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    return inflater.inflate(R.layout.frag_detail, container,false); 
  } 
   
  public void setText(String item){ 
    TextView txt = (TextView) getView().findViewById(R.id.txt_detail); 
    txt.setText(item); 
  } 
 
   
} 

 
其他的部分就是一些数组,String的定义了,这个demo虽然简单,却将Android Fragment方面常用到的做了一个综述,如果自己写明白了这个的话,今后遇到类似的项目应该要好应付的多,好了,收工!



注:相关教程知识阅读请移步到Android开发频道。