我不确定为什么BackPressCloesHandler不工作

时间:2014-10-17 15:50:08

标签: android eclipse

我不确定为什么BackPressCloesHandler无法正常工作。

我不知道出了什么问题。

我编辑的比原版少,所以这段代码有一些错误,但绝对有效。

BackPressCloesHandler位于终点。

package com.test;

import com.test.R;

import android.net.Uri;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.app.ActionBar;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.MenuInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.MenuItem;

import android.app.AlertDialog;
import android.view.LayoutInflater;

public class MainActivity extends TabActivity 

{
    private BackPressCloseHandler backPressCloseHandler;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startActivity(new Intent(this,Loading.class));
        setContentView(R.layout.MainActivity);

        backPressCloseHandler = new BackPressCloseHandler(this);

        TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

        ActionBar actionBar = getActionBar();
        getActionBar().setDisplayShowHomeEnabled(false);
        actionBar.setBackgroundDrawable(new ColorDrawable(0x66DADADA));

        TabSpec tab1 = tabHost.newTabSpec("Tab1");
        TabSpec tab2 = tabHost.newTabSpec("Tab2");
        TabSpec tab3 = tabHost.newTabSpec("Tab3");
        TabSpec tab4 = tabHost.newTabSpec("Tab4");
        TabSpec tab5 = tabHost.newTabSpec("Tab5");

        tab1.setIndicator("1");
        tab1.setContent(new Intent(this,Tab1.class)); 

        tab2.setIndicator("2");
        tab2.setContent(new Intent(this,Tab2.class));

        tab3.setIndicator(“3”);
        tab3.setContent(new Intent(this,Tab3.class));

        tab4.setIndicator(“4”);
        tab4.setContent(new Intent(this,Tab4.class));

        tab5.setIndicator(“5);
        tab5.setContent(new Intent(this,Tab5.class));

        tabHost.addTab(tab1);
        tabHost.addTab(tab2);
        tabHost.addTab(tab3);
        tabHost.addTab(tab4);
        tabHost.addTab(tab5);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);

        return super.onCreateOptionsMenu(menu);
        //return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.intro:

            Context Context_intro = getApplicationContext();
            LayoutInflater inflater_intro = (LayoutInflater) Context_intro.getSystemService(LAYOUT_INFLATER_SERVICE);

            View layout = inflater_intro.inflate(R.layout.more_intro,(ViewGroup) findViewById(R.id.more_intro));
            AlertDialog.Builder Dialog_intro = new AlertDialog.Builder(MainActivity.this);

            Dialog_intro.setTitle("Introduction"); 
            Dialog_intro.setView(layout);

        AlertDialog ad_intro = Dialog_intro.create();
        ad_intro.show();!

            break;

        case R.id.email:
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto", “tttt@gmail.com", null));
        intent.putExtra(Intent.EXTRA_SUBJECT, “test1”);
        intent.putExtra(Intent.EXTRA_TEXT, “test”2);
        startActivity(Intent.createChooser(intent, "Choose an Email Client"));
        break;

        case R.id.dev:
            Context Context_dev = getApplicationContext();
            LayoutInflater inflater_dev = (LayoutInflater) Context_dev.getSystemService(LAYOUT_INFLATER_SERVICE);

            View layout_dev = inflater_dev.inflate(R.layout.more_dev,(ViewGroup) findViewById(R.id.more_dev));
            AlertDialog.Builder Dialog_dev = new AlertDialog.Builder(MainActivity.this);

            Dialog_dev.setTitle("About Developer");
            Dialog_dev.setView(layout_dev); 

            AlertDialog ad_dev = Dialog_dev.create();
            ad_dev.show();
            break;

        case R.id.ver:
            Context Context_ver = getApplicationContext();
            LayoutInflater inflater_ver = (LayoutInflater) Context_ver.getSystemService(LAYOUT_INFLATER_SERVICE);

            View layout_ver = inflater_ver.inflate(R.layout.more_appver,(ViewGroup) findViewById(R.id.more_appver));
            AlertDialog.Builder Dialog_ver = new AlertDialog.Builder(MainActivity.this);

            Dialog_ver.setTitle("Application Version");
            Dialog_ver.setView(layout_ver); 

            AlertDialog ad_ver = Dialog_ver.create();
            ad_ver.show();
            break;

        default:
            break;
        }

        return true;
    }   

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        backPressCloseHandler.onBackPressed();

    }

}

度过愉快的一天。

0 个答案:

没有答案