注册 登录
编程论坛 Android开发

按钮设置OnClickListener事件监听器时 -> 运行测试死机问题

七夜之华 发布于 2016-02-03 18:19, 5062 次点击
代码如下:
package cn.itcast.tao;

import javax.crypto.NullCipher;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

    public EditText haomakuang ;
    public Button queren = null ;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        haomakuang = (EditText) findViewById(R.id.haomakuang);
        queren = (Button) findViewById(R.id.queren);
//        
//        queren.setOnClickListener(new OnClickListener(){
//
//            @Override
//            public void onClick(View v) {
//                String haoma = haomakuang.getText().toString();
//                System.out.println("号码是"+haoma);
//            }   
//        });
        
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }
}
只有本站会员才能查看附件,请 登录


1 回复
#2
七夜之华2016-02-03 18:22
回复 楼主 七夜之华
设置监听器后代码为:
package cn.itcast.tao;

import javax.crypto.NullCipher;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

    public EditText haomakuang ;
    public Button queren = null ;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        haomakuang = (EditText) findViewById(R.id.haomakuang);
        queren = (Button) findViewById(R.id.queren);
        
        queren.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
            String haoma = haomakuang.getText().toString();
                System.out.println("号码是"+haoma);
            }   
        });
   
      if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }
}
只有本站会员才能查看附件,请 登录



1