Fragment例子

作者:源码世界时间:2014-03-13分类:程序员碎语评论:0浏览:5999
package com.zirx.multiframents;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class LeftListFragment extends ListFragment {

	String[] listitem = { "AAAA", "BBBB", "CCCC", "DDDD" };

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);

		ContentFragment cf = ContentFragment.newInstance(id);
		FragmentTransaction ft = getFragmentManager().beginTransaction();
		ft.replace(R.id.contentfragment, cf);
		ft.commit();
		
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onViewCreated(view, savedInstanceState);
		this.setListAdapter(new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, listitem));
	}


}
标签:Java  
返回顶部
分享按钮