我有两个正在使用的类,我的主要 SherlockFragmentActivity 和一个 SherlockListFragment。我正在尝试使用操作栏导航栏简单地从一个移动到另一个。
问题是当我单击每个选项卡时,什么都没有发生。它只是选择保留相同视图的其他选项。由于我的 Log.i(),我知道它会进入 ontabselected
这是我的两个课程: 主要活动:
public class MainActivity extends SherlockFragmentActivity implements ActionBar.TabListener {
private ActionBar actionbar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.actionbar = getSupportActionBar();
this.actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
this.actionbar.addTab(this.actionbar.newTab().setText("Balance").setTabListener(this));
this.actionbar.addTab(this.actionbar.newTab().setText("Transactions").setTabListener(this));
}
protected void onResume()
{
super.onResume();
}
protected void onPause()
{
super.onPause();
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if(tab.getText().equals("Balance")){}
else if(tab.getText().equals("Transactions"))
{
SherlockListFragment f = new TransactionList();
ft.replace(android.R.id.content, f, "TransactionList");
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction f) {
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
列出活动:
public class TransactionList extends SherlockListFragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_transaction_list, container, false);
}
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
DataSource ds = new DataSource(getSherlockActivity());
ds.open();
List<Transaction> transactions = ds.findAll();
ds.close();
ArrayAdapter<Transaction> adapter = new ArrayAdapter<Transaction>(getSherlockActivity(), android.R.layout.simple_list_item_1, transactions.toArray(new Transaction[transactions.size()]));
setListAdapter(adapter);
}
}
列表布局:
<ListView
android1:id="@android:id/list"
android1:layout_width="match_parent"
android1:layout_height="wrap_content">
</ListView>
</LinearLayout>
显现:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dawkinstan.simplebalance"
android:versionCode="4"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<application
android:icon="@drawable/wallet_icon"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light"
android:logo="@drawable/wallet_icon">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MTSettings"
android:label="@string/title_activity_mtsettings" >
<intent-filter>
<action android:name="com.dawkinstan.MTSettings" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TransactionList"
android:label="@string/title_activity_transaction" >
<intent-filter>
<action android:name="com.dawkinstan.TransactionList" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>