首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修改Sherlock Master详细信息流

修改Sherlock Master详细信息流
EN

Stack Overflow用户
提问于 2012-11-12 23:03:27
回答 1查看 820关注 0票数 0

如果你用过神探夏洛克大师的细节流程,请帮助我。

我已经添加了选项卡,并删除了详细信息片段/活动中的数据,但是当我尝试在选项卡中放大一个按钮时,它不起作用。

你能帮帮我吗?下面是我修改过的列表活动,以便在两个窗格模式下显示选项卡。

代码语言:javascript
复制
package com.example.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;

/**
 * An activity representing a list of Courses. This activity has different
 * presentations for handset and tablet-size devices. On handsets, the activity
 * presents a list of items, which when touched, lead to a
 * {@link CourseDetailActivity} representing item details. On tablets, the
 * activity presents the list of items and item details side-by-side using two
 * vertical panes.
 * <p>
 * The activity makes heavy use of fragments. The list of items is a
 * {@link CourseListFragment} and the item details (if present) is a
 * {@link CourseDetailFragment}.
 * <p>
 * This activity also implements the required
 * {@link CourseListFragment.Callbacks} interface to listen for item selections.
 */
public class CourseListActivity extends SherlockFragmentActivity implements
    CourseListFragment.Callbacks {

/**
 * Whether or not the activity is in two-pane mode, i.e. running on a tablet
 * device.
 */
private boolean mTwoPane;
private boolean once = true;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course_list);

    if (findViewById(R.id.course_detail_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;

        // In two-pane mode, list items should be given the
        // 'activated' state when touched.
        ((CourseListFragment) getSupportFragmentManager().findFragmentById(
                R.id.course_list)).setActivateOnItemClick(true);
    }

    // TODO: If exposing deep links into your app, handle intents here.
}

/**
 * Callback method from {@link CourseListFragment.Callbacks} indicating that
 * the item with the given ID was selected.
 */
@Override
public void onItemSelected(String id) {
    if (mTwoPane) {
        // In two-pane mode, show the detail view in this activity by
        // adding or replacing the detail fragment using a
        // fragment transaction.
        CourseDetailFragment fragment = new CourseDetailFragment();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.course_detail_container, fragment).commit();
        if (once) {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        // initiating both tabs and set text to it.
        ActionBar.Tab assignTab = actionBar.newTab().setText("Assignments");
        ActionBar.Tab schedTab = actionBar.newTab().setText("Schedule");
        ActionBar.Tab contactTab = actionBar.newTab().setText("Contact");

        // Create three fragments to display content
        Fragment assignFragment = new Assignments();
        Fragment schedFragment = new Schedule();
        Fragment contactFragment = new Contact();

        assignTab.setTabListener(new MyTabsListener(assignFragment));
        schedTab.setTabListener(new MyTabsListener(schedFragment));
        contactTab.setTabListener(new MyTabsListener(contactFragment));

        actionBar.addTab(assignTab);
        actionBar.addTab(schedTab);
        actionBar.addTab(contactTab);
        once = false;
        }
    } else {
        // In single-pane mode, simply start the detail activity
        // for the selected item ID.
        Intent detailIntent = new Intent(this, CourseDetailActivity.class);
        startActivity(detailIntent);
    }

}
class MyTabsListener implements ActionBar.TabListener {
    public Fragment fragment;

    public MyTabsListener(Fragment fragment) {
        this.fragment = fragment;
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
            ft.replace(R.id.twopanecontainer, fragment);
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(fragment);
}
}
}

下面是默认情况下保存文本视图的片段课程详细布局。

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/twopanecontainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/course_detail"
        style="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp"
        tools:context=".CourseDetailFragment" />

</LinearLayout>

我应该修改什么,才能为每个选项卡膨胀不同的视图?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-02-21 11:18:46

在您的活动布局中有一个ViewPager,然后实现FragmentPagerAdapter

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13346061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档