2 o casper ne O_Casper_ne 于 2013.04.18 15:37 提问

Alert dialog 中的 button 不能运行

我一直想把附件放在程序中,但是首先需要让 dialog buttons 起作用,求助如何实现按钮功能?

Chrono = (Chronometer) findViewById(R.id.chronometer1);
        Chrono.start();
        while (!(Chrono.equals(chronoText))) {
            chronoText = Chrono.getText().toString();
            if (chronoText.equals("00:30")) {
                Intent intent = new Intent(getApplicationContext(),
                        Hw3Activity.class);
                startActivity(intent);
            }
        }

整个代码:

 public class Next extends Activity {
        Button returned;
        Button click;
        Button search;
        EditText clicksearch;
        TextView counted;
        int counter;
        int answer;
        Chronometer Chrono;
        CharSequence chronoText;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.screentwo);
            // waiter = new Waiter(60 * 1000); // 1 min
            // waiter.start();

            Chrono = (Chronometer) findViewById(R.id.chronometer1);
            Chrono.start();
            Log.d("Ebz", "uhh");
            returned = (Button) findViewById(R.id.returned);
            click = (Button) findViewById(R.id.click);
            search = (Button) findViewById(R.id.search);
            clicksearch = (EditText) findViewById(R.id.clicksearch);
            counted = (TextView) findViewById(R.id.counted);
    chronometer(); // its called here
returned.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    counter = 0;
                    Intent intent = new Intent(getBaseContext(), Hw3Activity.class);
                    answer = intent.getIntExtra("meaningOfLife", -1);

                    Intent i = getIntent();
                    i.putExtra("returnInt", answer);
                    setResult(RESULT_OK, i);
                    startActivity(intent);

                }
            });
            click.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    counter++;
                    counted.setText(String.valueOf(counter));
                    Chrono.setBase(SystemClock.elapsedRealtime());

                }
            });
            search.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                    intent.putExtra(SearchManager.QUERY, clicksearch.getText()
                            .toString());
                    startActivity(intent);
                }
            });
            clicksearch.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

                }
            });
        }

        public void chronometer() {
            while (!(Chrono.equals(chronoText))) {
                chronoText = Chrono.getText();
                Log.d("Ebz", "makes it to chronometer");
                counted.setText(String.valueOf(chronoText));
                if (chronoText.equals("00:10")) {
                    Intent intent = new Intent(getApplicationContext(),
                            Hw3Activity.class);
                    startActivity(intent);
                }

            }
        }
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!