作业8

<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.vb.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="75dp"
        android:text="手机号码" />
    <EditText
         android:id="@+id/et1"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
         android:layout_marginTop="75dp"
         android:layout_marginLeft="100dp"
        android:text=""
        
      />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="149dp"
        android:text="充值" 
        android:onClick="aaa"/>

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/et1"
        android:layout_alignTop="@+id/button1"
        android:layout_marginTop="84dp"
        />

</RelativeLayout>




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="39dp"
        android:layout_marginTop="126dp"
        android:text="充值金额" />
    <EditText 
        android:id="@+id/et2"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
         android:layout_marginTop="126dp"
         android:layout_marginLeft="120dp"
        />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="126dp"
        android:layout_marginLeft="16dp"
        android:text="充值" 
        android:onClick="bbb"/>

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignParentTop="true"
        android:layout_marginTop="49dp"
        />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentRight="true"
        android:layout_marginRight="41dp"
        android:text="取消充值" 
         android:onClick="ccc"/>

</RelativeLayout>
package com.example.vb;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
private EditText et1;
private TextView tv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button=(Button)findViewById(R.id.button1);
        button.setText("充值");
        button.setOnClickListener(new MyButtonListener());     
        et1=(EditText) findViewById(R.id.et1);
        tv1=(TextView)findViewById(R.id.tv1);
    }
    public class MyButtonListener implements OnClickListener {

        @Override
        //传送 电话号码
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent=new Intent();
              intent.setClass(MainActivity.this,SecondActivity.class);
              intent.putExtra("number", et1.getText().toString());   
            startActivityForResult(intent,1);
        }
        
        
    }

    
     protected void onActivityResult(int requestCode, int resultCode,  Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == 1 && resultCode == 2) {
                String tv1 = data.getStringExtra("data");

                Toast.makeText(this, tv1, 0).show();
                
            }
                if (requestCode == 1 && resultCode == 3) {
                    
                    tv1.setText("充值失败");

                }
            }

  }

            
            
            
            
   package com.example.vb;

import com.example.vb.MainActivity.MyButtonListener;

import android.app.Activity;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; 

public class SecondActivity extends Activity {
     private TextView tv2;
     private EditText et2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.secondlayout);
        tv2 = (TextView) findViewById(R.id.tv2);
        et2=(EditText)findViewById(R.id.et2);
        Intent intent=getIntent();
        tv2.setText(intent.getStringExtra("number"));
        
    }
    
    public void bbb(View v) {
        Intent intent =  new Intent();
        intent.putExtra("data", et2.getText().toString());
        setResult(2, intent);
        finish();
    }
    
    public void ccc(View v) {
        Intent intent=new Intent();
        setResult(3,intent);
        finish();
    }
}

            
    
    
        

        
    

 

posted @ 2019-10-18 18:36  郭少锋18840631471  阅读(124)  评论(0编辑  收藏  举报