我在自定義標題欄上創建主頁按鈕(使用圖片到按鈕)。 我的問題是每次點擊這個按鈕。它將會主要。 當停留在主頁面並點擊按鈕。它會一次又一次地到主頁。 我該怎麼辦? 在主頁面時我不想去主要或者不能在主頁面點擊這個按鈕。自定義標題欄上的Android主頁按鈕
你明白嗎?
請幫我 謝謝
public class CustomTitleBar extends Activity {
protected ImageButton toHome;
protected TextView title;
protected ImageView icon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
toHome = (ImageButton) findViewById(R.id.header);
title = (TextView) findViewById(R.id.title);
icon = (ImageView) findViewById(R.id.icon);
ProgressBar titleProgressBar = (ProgressBar) findViewById(R.id.loadProgress);
titleProgressBar.setVisibility(ProgressBar.GONE);
/* -- Button to HOME -- */
toHome.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent goHome = new Intent(Intent.ACTION_MAIN);
goHome.setClass(CustomTitleBar.this, MainActivity.class);
startActivity(goHome);
finish();
}
});
}
}
纔有人告訴我用面漆();但它無法解決我的問題。
從例如:主>第1頁>(點擊家)>主>第2頁>(點擊家)>主
當移動
週期點擊返回按鈕是:主>第2頁>主>第1頁>主要>出於應用程序。
當我使用finish()後,在手機上點擊返回按鈕;
循環爲:main> main> main> out of app。
非常感謝,但如何使用它? – 2011-06-05 15:59:53
哈哈,這是:toHome.setOnClickListener(新OnClickListener(){ 公共無效的onClick(視圖v){ 意向意圖=新意圖(這一點,MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity (intent); finish(); } }); – anticafe 2011-06-05 16:29:03
構造函數Intent(new View.OnClickListener(){},Class)未定義.... –
2011-06-05 16:41:12