android程序
/*activity_main.xml--------------------------------------------*/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#00BBFF"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/et_id"
android:inputType="none"
android:layout_margin="10px"
android:hint="please input your expect money"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="点击一下加1元"
android:id="@+id/btn_id"
android:layout_margin="10px"/>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="点击一下减1元"
android:id="@+id/btn1_id"
android:layout_margin="10px"
/>
<TextView
android:text="我通过点击鼠标赚了..."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_id"
android:textColor="#0000FF"
android:textSize="20dp"
android:layout_gravity="center"
android:layout_margin="10px"/>
</LinearLayout>
/*MainActivity.java--------------------------------------------*/
package com.example.administrator.helloworld;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private Button btn;
private TextView tv;
private int money = 0;
private Button btn1;
private EditText et;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.btn_id);
tv = (TextView)findViewById(R.id.tv_id);
btn1 = (Button)findViewById(R.id.btn1_id);
et = (EditText)findViewById(R.id.et_id);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int etmoney = Integer.parseInt(et.getText().toString().trim());
if(etmoney == money)
Toast.makeText(MainActivity.this,"success",Toast.LENGTH_SHORT).show();
money++;
tv.setText("earn"+money+"dollor");
}
});
btn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
if(money == 0)
Toast.makeText(MainActivity.this,"error",Toast.LENGTH_SHORT).show();
else {
money--;
tv.setText("earn"+money+"dollor");
}
}
});
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。