• 第七次作业(2)


    <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();
        }
    
        
    }

  • 相关阅读:
    java中的subList
    值传递和引用传递
    java程序中有异常处理和没有异常处理的区别
    正则表达式
    poj 3187 三角数问题
    poj 2718 切数问题 穷竭搜索
    ACM 广度优化搜索算法总结
    poj 3669 火星撞地球问题 bfs算法
    poj 2251 三维地图最短路径问题 bfs算法
    ACM 深度优化搜索算法小总结
  • 原文地址:https://www.cnblogs.com/zqxxx/p/11718847.html
Copyright © 2020-2023  润新知