第七次作业--手机充值

我与影子孤独终老i 提交于 2019-12-02 16:59:26
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.task.MainActivity" >
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/tw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请输入您的手机号"/>
        <EditText 
            android:id="@+id/phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="充值"
        android:onClick="Recharge"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>
 
 
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.task.MyActivity" >
  <LinearLayout 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal">
       <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="您的号码是:" />
        <TextView
        android:id="@+id/phones"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
  </LinearLayout>
   <EditText 
       android:id="@+id/money"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:hint="请输入要充值的金额"
       android:layout_centerInParent="true"/>
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:onClick="yes"
       android:layout_alignParentBottom="true"
       android:text="充值"/>
    <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:onClick="no"
       android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
       android:text="取消充值"/>

</RelativeLayout>
 
 
package com.example.task;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

    
    private String mPhone;
    private EditText Phone;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Phone=(EditText) findViewById(R.id.phone);
        
    }
 public void Recharge(View v) {
     Intent intent =new Intent(this, MyActivity.class);
     mPhone= Phone.getText().toString();
     intent.putExtra("phone", mPhone);
     startActivityForResult(intent,1);
 }
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
     Log.v("520lj", resultCode+"");
        switch (resultCode) {
        case 1:
            String  money=data.getStringExtra("money");
            Toast.makeText(this, "您充值的金额是"+money+"", 0).show();
            break;
        default:
            Toast.makeText(this, "充值失败", 0).show();
            break;
        }
}

}
 
 
package com.example.task;

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MyActivity extends Activity {

    private EditText Money;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        TextView phones = (TextView) findViewById(R.id.phones);
        Intent intent = getIntent();
        String phone =intent.getStringExtra("phone");
        phones.setText(phone);
        Money = (EditText) findViewById(R.id.money);
    }
    public void yes(View v) {
        Intent intent = new Intent();
        intent.putExtra("money",Integer.parseInt(Money.getText().toString())+"");
        Log.v("520lj", intent+"");
        setResult(1,intent);
        finish();
    }
    public void no(View v) {
        Intent intent = new Intent();
        setResult(2, intent);
        finish();
    }

    
}

 

 

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!