android简单计算器说课材料
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
a n d r o i d简单计算器
欢迎大家补充
package com.example.zzz;
//此文使用了fragment的模块。
//此文使用了fragment的模块。
//此文使用了fragment的模块。
//此文使用了fragment的模块。
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import youtInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(yout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment { //此文使用了fragment的模块。
private double a,b;
private int num=0;
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private Button button5;
private Button button6;
private Button button7;
private Button button8;
private Button button9;
private Button button0;
private Button buttonjia;
private Button buttonjian;
private Button buttoncheng;
private Button buttonchu;
private Button buttonxiaoshudian;
private Button buttonqingchu;
private Button buttondengyu;
private TextView text;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView =
inflater.inflate(yout.fragment_main, container,
false);
findbutton(rootView);//定义一个函数用于找组件
ViewEvent(rootView);//定义一个函数。用于初始化监听
器(将组件与监听器相连接)
//注意,设置监听器的时候必须保证找到了组件。否则程序
用易出错。特别提醒
return rootView;//使用fragment,此处的返回值必须为rootView,上面有函数可以看一下、
}
private void findbutton(View rootView){
button0=(Button)rootView.findViewById(R.id.button0);
button1=(Button)rootView.findViewById(R.id.button1);
button2=(Button)rootView.findViewById(R.id.button2);
button3=(Button)rootView.findViewById(R.id.button3);
button4=(Button)rootView.findViewById(R.id.button4);
button5=(Button)rootView.findViewById(R.id.button5);
button6=(Button)rootView.findViewById(R.id.button6);
button7=(Button)rootView.findViewById(R.id.button7);
button8=(Button)rootView.findViewById(R.id.button8);
button9=(Button)rootView.findViewById(R.id.button9);
button0=(Button)rootView.findViewById(R.id.button0);
buttonjia=(Button)rootView.findViewById(R.id.buttonjia);
buttonjian=(Button)rootView.findViewById(R.id.buttonjian);
buttoncheng=(Button)rootView.findViewById(R.id.buttoncheng);