タブを作成するアクティビティがあり、各タブはアクティビティに対応しています
タブを作成するアクティビティ:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ActionBar bar = getSupportActionBar();
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Resources res = getResources();
LocalActivityManager mlam = new LocalActivityManager(this, false);
final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
mlam.dispatchCreate(savedInstanceState);
tabHost.setup(mlam);
TabHost.TabSpec spec;
Intent intent;
// TabHost tabHost = getTabHost();
// tabHost.setup();
TabSpec specAll = tabHost.newTabSpec("All");
specAll.setIndicator("All");
Intent allIntent = new Intent(this, allActivity.class);
specAll.setContent(allIntent);
// specAll.setContent(R.id.allList);
Log.d("SpecAll", "" + specAll.setContent(allIntent));
TabSpec specIn = tabHost.newTabSpec("in");
specIn.setIndicator("In");
Intent inIntent = new Intent(this, inActivity.class);
specIn.setContent(inIntent);
TabSpec specOut = tabHost.newTabSpec("Out");
specOut.setIndicator("Out");
Intent outIntent = new Intent(this, outActivity.class);
specOut.setContent(outIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(specAll); // Adding all tab
tabHost.addTab(specIn); // Adding in tab
tabHost.addTab(specOut); // Adding out tab
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
int i = tabHost.getCurrentTab();
// Log.i("@@@@@@@@ ANN CLICK TAB NUMBER", "------" + i);
if (i == 0) {
Log.d("TAB", "" + i);
} else if (i == 1) {
Log.d("TAB", "" + i);
} else
Log.d("TAB", "" + i);
}
});
}
タブのアクティビティを呼び出すときに、なぜ OnResume() メソッドに入ることができないのかを知る必要があります。OnCreate と onStart でのみ入力できます。以下のコードでは、onResume 内の Log.d は表示されません。
タブのアクティビティ:
ProgressDialog pDialog;
EfficientAdapter adap;
Databasehandler db;
ArrayList<Message> menuItems = new ArrayList<Message>();
int current_page = 0;
int index = 0;
int limit = 0;
private static final int TYPE_MO = 0;
private static final int TYPE_MT = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.all);
}
@Override
public void onStart() {
super.onStart();
db = new Databasehandler(this);
List<Message> messages;
messages = db.getMessages(0, 5);
index += 5;
limit = limit + 5;
for (Message mg : messages) {
// Log.d("mpika",mg.getBody());
menuItems.add(new Message(mg.getID(), mg.getPhoneNumber(), mg
.getBody(), mg.getStatus(), mg.getIsMO(), mg.getDate()));
}
adap = new EfficientAdapter(this, menuItems);
ListView lv = (ListView) findViewById(R.id.listall);
// Creating a button - Load More
Button btnLoadMore = new Button(this);
btnLoadMore.setText("Load More");
// Adding button to listview at footer
lv.addFooterView(btnLoadMore);
lv.setAdapter(adap);
btnLoadMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Starting a new async task
// CharSequence text = "Ok dude you pressed me ";
// Toast toast = Toast.makeText(getApplicationContext(), text,
// Toast.LENGTH_SHORT);
// toast.show();
new loadMoreListView().execute();
}
});
db.close();
}
@Override
public void onResume()
{
super.onResume();
Log.d("OnResume", "inside onResume");
}