{"id":9419,"date":"2023-11-20T14:51:28","date_gmt":"2023-11-20T06:51:28","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=9419"},"modified":"2023-11-20T14:51:28","modified_gmt":"2023-11-20T06:51:28","slug":"app%e5%bc%80%e5%8f%91%e4%be%8b%e5%ad%90%e4%bb%a3%e7%a0%81%e6%9c%89%e4%bb%80%e4%b9%88%e4%bd%9c%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/11\/20\/app%e5%bc%80%e5%8f%91%e4%be%8b%e5%ad%90%e4%bb%a3%e7%a0%81%e6%9c%89%e4%bb%80%e4%b9%88%e4%bd%9c%e7%94%a8%ef%bc%9f\/","title":{"rendered":"app\u5f00\u53d1\u4f8b\u5b50\u4ee3\u7801\u6709\u4ec0\u4e48\u4f5c\u7528\uff1f"},"content":{"rendered":"

\u73b0\u4eca\uff0c\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\uff08APP\uff09\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u800cAPP\u5f00\u53d1\u8005\u4e5f\u8d8a\u6765\u8d8a\u591a\u3002\u90a3\u4e48APP\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462\uff1f\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684APP\u5b9e\u73b0\u4ee3\u7801\u8303\u4f8b\u3002<\/p>\n

\u6211\u4eec\u4ee5\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668APP\u4e3a\u4f8b\uff0c\u6765\u4ecb\u7ecdAPP\u5f00\u53d1\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002\u6211\u4eec\u5c06\u91c7\u7528Android Studio\u4e2d\u7684Java\u8bed\u8a00\u8fdb\u884c\u7f16\u7a0b\u3002<\/p>\n

1. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Android\u9879\u76ee\u3002 \u5728Android Studio \u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u7136\u540e\u5728 XML Layout \u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u8ba1\u7b97\u5668\u7684\u754c\u9762\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e24\u4e2a EditText \u6765\u8f93\u5165\u6570\u5b57\uff0c\u548c\u56db\u4e2a Button \u6765\u6267\u884c\u52a0\u3001\u51cf\u3001\u4e58\u3001\u9664\u64cd\u4f5c\u3002 <\/p>\n

“`<\/p>\n<\/p>\n

android:id=”@+id\/editText1″<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:inputType=”number” \/><\/p>\n<\/p>\n

android:id=”@+APP\u5f00\u53d1<\/a>id\/editText2″<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:inputType=”number” \/><\/p>\n<\/p>\n

android:id=”@+id\/buttonAdd”<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:text=”+” \/><\/p>\n<\/p>\n

android:id=”@+id\/buttonSub”<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:text=”-” \/><\/p>\n<\/p>\n

android:id=”@+id\/buttonMul”<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:text=”*” \/><\/p>\n<\/p>\n

android:id=”@+id\/buttonDiv”<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:text=”\/” \/><\/p>\n

“`<\/p>\n

2. \u5728 MainActivity \u7c7b\u4e2d\u7f16\u5199\u8ba1\u7b97\u529f\u80fd\u3002\u6211\u4eec\u5728 MainActivity \u7c7b\u7684 onCreate \u65b9\u6cd5\u4e2d\u6dfb\u52a0\u70b9\u51fb\u4e8b\u4ef6\uff0c\u4f7f\u7528 EditText \u4e2d\u7684\u503c\u6765\u8fdb\u884c\u8ba1\u7b97\u64cd\u4f5c\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

“`<\/p>\n

public class MainActivity extends AppCompatActivity {<\/p>\n

private EditText editText1, editText2;<\/p>\n

private Button buttonAdd, buttonSub, buttonMul, buttonDiv;<\/p>\n

@Override<\/p>\n

protected void onCreate(Bundle savedInstanceState) {<\/p>\n

super.onCreate(savedInstanceState);<\/p>\n

setContentView(R.layout.activity_main);<\/p>\n

editText1 = (EditText)findViewById(R.id.editText1);<\/p>\n

editText2 = (EditText)findViewById(R.id.editText2);<\/p>\n

buttonAdd = (Button)findViewById(R.id.buttonAdd);<\/p>\n

buttonSub = (Button)findViewById(R.id.buttonSub);<\/p>\n

buttonMul = (Button)findViewById(R.id.buttonMul);<\/p>\n

buttonDiv = (Button)findViewById(R.id.buttonDiv);<\/p>\n

buttonAdd.setOnClickListener(new View.OnClickListener() {<\/p>\n

@Override<\/p>\n

public void onClick(View v) {<\/p>\n

int num1 = Integer.parseInt(editText1.getText().toString());<\/p>\n

int num2 = Integer.parseInt(editText2.getText().toString());<\/p>\n

int result = num1 + num2;<\/p>\n

Toast.makeText(MainActivity.this, StrinAPP<\/a>g.valueOf(result), Toast.LENGTH_SHORT).show();<\/p>\n

}<\/p>\n

});<\/p>\n

buttonSub.setOnClickListener(new View.OnClickListener() {<\/p>\n

@Override<\/p>\n

public void onClick(View v) {<\/p>\n

int num1 = Integer.parseInt(editText1.getText().toString());<\/p>\n

int num2 = Integer.parseInt(editText2.getText().toString());<\/p>\n

int result = num1 – num2;<\/p>\n

Toast.makeText(MainActivity.this, String.valueOf(result), Toast.LENGTH_SHORT).show();<\/p>\n

}<\/p>\n

});<\/p>\n

buttonMul.setOnClickListener(new View.OnClickListener() {<\/p>\n

@Override<\/p>\n

public void onClick(View v) {<\/p>\n

int num1 = Integer.parseInt(editText1.getText().toString());<\/p>\n

int num2 = Integer.parseInt(editText2.getText().toString());<\/p>\n

int result = num1 * num2;<\/p>\n

Toast.makeText(MainActivity.this, String.valueOf(result), Toast.LENGTH_SHORT).show();<\/p>\n

}<\/p>\n

});<\/p>\n

buttonDiv.setOnClickListener(new View.OnClickListener() {<\/p>\n

@Override<\/p>\n

public void onClick(View v) {<\/p>\n

int num1 = Integer.parseInt(editText1.getText().toString());<\/p>\n

int num2 = Integer.parseInt(editText2.getText().toString());<\/p>\n

int result = num1 \/ num2;<\/p>\n

Toast.makeText(MainActivity.this, String.valueOf(result), Toast.LENGTH_SHORT).show();<\/p>\n

}<\/p>\n

}<\/p>\n

<\/figure>\n<\/p>\n

);<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86 OnClickListener \u63a5\u53e3\u6765\u5b9e\u73b0\u56db\u4e2a\u6309\u94ae\u7684\u70b9\u51fb\u64cd\u4f5c\uff0c\u4f7f\u7528\u4e86 EditText \u4e2d\u7684 getText() \u65b9\u6cd5\u6765\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u6570\u503c\uff0c\u4f7f\u7528\u4e86 Toast \u6765\u5c55\u793a\u8ba1\u7b97\u7ed3\u679c\u3002<\/p>\n

3. \u8fd0\u884cAPP\u3002\u6700\u540e\uff0c\u5728 Android Studio \u4e2d\u7f16\u8bd1\u5e76\u8fd0\u884c\u4ee3\u7801\uff0c\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668APP\u3002\u4f60\u53ef\u4ee5\u8f93\u5165\u6570\u5b57\u548c\u64cd\u4f5c\u7b26\uff0c\u7136\u540e\u70b9\u51fb\u64cd\u4f5c\u7b26\u6309\u94ae\u6765\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n

\u4ee5\u4e0a\u4fbf\u662f\u4e00\u4e2a\u7b80\u5355\u7684APP\u5f00\u53d1\u5b9e\u73b0\u793a\u4f8b\u3002\u5728\u5b9e\u9645APP\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u9700\u8981\u66f4\u52a0\u590d\u6742\u7684\u4ee3\u7801\u548c\u529f\u80fd\uff0c\u4f46\u4ee5\u4e0a\u7684\u8fc7\u7a0b\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u521d\u6b65\u4e86\u89e3APP\u5f00\u53d1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4ee5\u540e\u8fdb\u884c\u66f4\u52a0\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u73b0\u4eca\uff0c\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\uff08APP\uff09\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u800cAPP\u5f00\u53d1\u8005\u4e5f\u8d8a\u6765\u8d8a\u591a\u3002\u90a3\u4e48APP\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462\uff1f\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684APP\u5b9e\u73b0\u4ee3\u7801\u8303\u4f8b\u3002\u6211\u4eec\u4ee5\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668APP\u4e3a\u4f8b\uff0c\u6765\u4ecb\u7ecdAPP\u5f00\u53d1\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002\u6211<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3002,4578,38,6106,2267],"topic":[],"class_list":["post-9419","post","type-post","status-publish","format-standard","hentry","category-kaifaapp","tag-html","tag-webapp","tag-38","tag-6106","tag-2267"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/9419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=9419"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/9419\/revisions"}],"predecessor-version":[{"id":9447,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/9419\/revisions\/9447"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=9419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=9419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=9419"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=9419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}