私は 2 つのアクティビティを作成しました。これらは sherlockActivity です。
タブを押すことができます。しかし、何も変わりません。
以下は私のソースです。
ごめん。そして感謝します。
MainActivity.java
package com.example.sherlocktest;
imports;
public class MainActivity extends SherlockActivity implements ActionBar.TabListener {
private ActionBar aBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cal);
/** TabBar */
aBar = getSupportActionBar();
aBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
aBar.setTitle("Darphin's bar");
ActionBar.Tab tab1 = aBar.newTab().setText("버튼1").setTabListener(this);
ActionBar.Tab tab2 = aBar.newTab().setText("버튼2").setTabListener(this);
ActionBar.Tab tab3 = aBar.newTab().setText("버튼3").setTabListener(this);
aBar.addTab(tab1);
aBar.addTab(tab2);
aBar.addTab(tab3);
}
@Override
public void onTabSelected(Tab tab, android.support.v4.app.FragmentTransaction ft) {
if(tab.equals(aBar.getTabAt(0))) {
Toast.makeText(this,"1",Toast.LENGTH_SHORT).show();
// setContentView(R.layout.activity_cal);
}
else if(tab.equals(aBar.getTabAt(1))) {
Toast.makeText(this,"2",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this , ListActivity.class);
startActivity(intent);
// setContentView(R.layout.activity_list);
}
else if(tab.equals(aBar.getTabAt(2))) {
Toast.makeText(this,"3",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onTabUnselected(Tab tab, android.support.v4.app.FragmentTransaction ft) {
}
@Override
public void onTabReselected(Tab tab, android.support.v4.app.FragmentTransaction ft) {
}
}
ListActivity.java
パッケージcom.example.sherlocktest;
imports
public class ListActivity extends SherlockActivity implements ActionBar.TabListener {
private ActionBar aBar;
private ListView listView;
private List arrayList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
/** TabBar */
aBar = getSupportActionBar();
aBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
aBar.setTitle("Darphin's bar");
ActionBar.Tab tab1 = aBar.newTab().setText("버튼1").setTabListener(this);
ActionBar.Tab tab2 = aBar.newTab().setText("버튼2").setTabListener(this);
ActionBar.Tab tab3 = aBar.newTab().setText("버튼3").setTabListener(this);
aBar.addTab(tab1);
aBar.addTab(tab2);
aBar.addTab(tab3);
/** ListView */
arrayList = new ArrayList<String>();
arrayList.add("first");
listView = new ListView(this);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.activity_list, arrayList);
listView.setAdapter(adapter);
}
@Override
public void onTabSelected(Tab tab, android.support.v4.app.FragmentTransaction ft) {
if(tab.equals(aBar.getTabAt(0))) {
Toast.makeText(this,"1",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ListActivity.this , MainActivity.class);
startActivity(intent);
}
else if(tab.equals(aBar.getTabAt(1))) {
Toast.makeText(this,"2",Toast.LENGTH_SHORT).show();
// setContentView(R.layout.activity_list);
}
else if(tab.equals(aBar.getTabAt(2))) {
Toast.makeText(this,"3",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onTabUnselected(Tab tab, android.support.v4.app.FragmentTransaction ft) {
}
@Override
public void onTabReselected(Tab tab, android.support.v4.app.FragmentTransaction ft) {
}
}
activity_cal.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<CalendarView
android:id="@+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
activity_list.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ListActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
</ListView>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView1"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:text="TextView" />
</RelativeLayout>
sherlockTestManifest.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ListActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
</ListView>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView1"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:text="TextView" />
</RelativeLayout>