我知道如何用片段列表替换整个活动布局,但是如何将片段列表嵌入到活动布局的一部分中?
编辑:我附上了我想在底部实现的内容的图片
这就是我知道该怎么做:
我有一个动作栏,下方有3个标签。 单击选项卡后,屏幕上会显示片段源(如FB应用程序的源)
这是我不知道该怎么做: 我有一个动作栏 在它下面我有一些内容,我想保持静态 在静态内容下面,我想要嵌套一个像上面描述的那样的提要。
以下是我尝试过的内容:
public class MyProfileActivity extends SherlockListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] values = new String[] { "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3",
"Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3",
"Samsung Galaxy S3", "Samsung Galaxy S3" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
R.layout.my_profile_feed_custom, R.id.tvProfileFeedItemName, values);
setListAdapter(adapter);
}
我想把它放在这里:
public class MyProfile extends ActionBarAndSlidingMenu implements OnClickListener{
private TableRow myProfileActionButtonsHolder;
private TableRow myProfileStatsHolder;
private TableRow myProfileActivityHolder;
public MyProfile() {
super(R.string.app_name);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_profile);
myProfileActionButtonsHolder = (TableRow) findViewById(R.id.userProfileActionButtonsHolder);
getSupportFragmentManager().beginTransaction().replace(R.id.userProfileActionButtonsHolder,
new MyProfileActionButtonsFragment()).commit();
//this one works - it places
//two buttons below the user info (it is a single fragment)
myProfileStatsHolder = (TableRow) findViewById(R.id.myProfileStatsHolder);
getSupportFragmentManager().beginTransaction().replace(R.id.myProfileStatsHolder,
new MyProfileUserStatsFragment()).commit();
//this one also works - it places user
//activity stats pane below the user info (it is a single fragment)
myProfileActivityHolder = (TableRow) findViewById(R.id.myProfileActivityHolder);
getSupportFragmentManager().beginTransaction().replace(R.id.myProfileActivityHolder,
new MyProfileActivity()).commit();
//this one doesnt work. It doesnt place the
//list of fragments below the stats pane. (it is a fragment list)
}
这是放置片段列表的地方:
public class Home扩展了ActionBarAndSlidingMenu {
public Home() {
super(R.string.app_name);
}
//String userEmail;
//String reqFrom = "";
CharSequence[] tabsText = {"Items", "People", "Places", };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab itemsFeedTab = actionBar.newTab();
ActionBar.Tab peopleFeedTab = actionBar.newTab();
ActionBar.Tab placesFeedTab = actionBar.newTab();
Fragment itemsFeedFragment = new FeedItems();
Fragment peopleFeedFragment = new FeedPeople();
Fragment placesFeedFragment = new FeedPlaces();
itemsFeedTab.setTabListener(new MyTabsListener(itemsFeedFragment));
peopleFeedTab.setTabListener(new MyTabsListener(peopleFeedFragment));
placesFeedTab.setTabListener(new MyTabsListener(placesFeedFragment));
actionBar.addTab(itemsFeedTab, 0, true);
actionBar.addTab(peopleFeedTab, 1, false);
actionBar.addTab(placesFeedTab, 2, false);
configurationz = new Configurationz();
for(int i = 0; i<actionBar.getTabCount(); i++){
LayoutInflater inflater = LayoutInflater.from(this);
View customView = inflater.inflate(R.layout.tab_title, null);
titleTV = (TextView) customView.findViewById(R.id.action_custom_title);
actionBar.getTabAt(i).setCustomView(customView);
}
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment){
this.fragment = fragment;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.replace(R.id.home, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) { }
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) { }
}
该片段看起来与上例中的片段相同。 在这里,当我单击一个选项卡时,它会用片段列表替换整个屏幕内容。
在上面的示例中,我只需要用片段列表替换屏幕的一部分,但我不知道如何。
答案 0 :(得分:2)
使用FrameLayout或ViewFlipper并在FrameLayout / ViewFlipper中使用自定义列表视图来加载数据