2012-11-12 47 views
0

如果您使用了sherlock主細節流程,請幫助我。修改Sherlock主細節流程

我已經添加了選項卡,並刪除了詳細的片段/活動內的數據,但是當我嘗試在選項卡內部充氣按鈕時,它不起作用。

你能幫我嗎? 以下是我在兩窗格模式下修改爲顯示選項卡的列表活動。

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); 
} 
} 
} 

下面是片段課程的詳細信息佈局,默認情況下包含textview。

<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> 

我應該修改什麼,以便爲每個選項卡填充不同的視圖?

感謝

回答

0

有一個ViewPager在YOUT活動佈局,然後實現FragmentPagerAdapter