ABSの使い方を学んでいます。コードは 4.1 で正常に動作していますが、2.2 で同じコードを実行すると、例外がスローされます。
これは MainActivity.java です
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class MainActivity extends SherlockFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ab.addTab(ab.newTab().setText("Beauty").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Cookery").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Health").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Relationship").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Yoga Spirituality").setTabListener(new Listner()));
}
class Listner implements TabListener {
public void onTabReselected(Tab tab, FragmentTransaction ft) { }
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft = getSupportFragmentManager().beginTransaction();
switch (tab.getPosition()) {
case 0:
ft.add(android.R.id.content, new BEAUTYFragment());
ft.commit();
break;
case 1:
ft.add(android.R.id.content, new COOKERYFragment());
ft.commit();
break;
case 2:
ft.add(android.R.id.content, new HEALTHFragment());
ft.commit();
break;
case 3:
ft.add(android.R.id.content, new RELATIONSHIPFragment());
ft.commit();
break;
case 4:
ft.add(android.R.id.content, new YOGAFragment());
ft.commit();
break;
default:
break;
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) { }
}
}
これはマニフェストです:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sher"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
</application>
</manifest>
LogCat のエラー:
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable