public class MainActivity extends Activity{private MainActivity(){};private static MainActivity mainActivity;public static MainActivity getmainActivity(){mainActivity=new MainActivity();return mainActivity;}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button dailButton= (Button) findViewById(R.id.bt_call);dailButton.setOnClickListener(new Mylistener());}}public class Mylistener implements OnClickListener {@Overridepublic void onClick(View v) {MainActivity mActivity=MainActivity.getmainActivity();EditText telEditText=(EditText)mActivity.findViewById(R.id.et_telNum);String number=telEditText.getText().toString();Intent intent=new Intent();intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:"+number));mActivity.startActivity(intent);}}着了监听类我不想把它放在mainActivity类的内部,但是在外部调用mainActivity的方法时还得new对象而且new出来的也不是同一个对象。能不能设计成单例的呢?这样好像编译不通过,有没有别的办法
添加回答
举报
0/150
提交
取消