• 20150602_Andriod 向窗体传递参数


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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignRight="@+id/button1"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="59dp"
            android:text="只读文本"
            android:textSize="15pt" 
            android:textColor="#0092c7" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button1"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="55dp"
            android:ems="10"
            android:hint="删除完成后显示,提示功能"
            android:text="文本框测试" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="85dp"
            android:hint="确定功能提示"
            android:text="@string/btn1Text"
            android:textStyle="bold" />

        <Button
            android:id="@+id/Button01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/button1"
            android:layout_below="@+id/button1"
            android:layout_marginTop="18dp"
            android:hint="弹窗功能提示"
            android:text="@string/btn2Text"
            android:textStyle="bold" />
       
            <Button
            android:id="@+id/Button02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/button1"
            android:layout_alignRight="@+id/Button01"
            android:layout_below="@+id/Button01"
            android:layout_marginTop="28dp"
            android:hint="下拉窗功能提示"
            android:text="@string/btn3Text"
            android:textStyle="bold" />

    </RelativeLayout>

    ///////////////////////////////////////////////////////////////////////////////////////////

    package com.example.test1;

    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.EditText;

    public class Popu_TC extends ActionBarActivity {
     
     ////////////////////
     private EditText Text_Popu;
     ////////////////////

     @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_popu__tc);
      
            ////////1///////////
      Text_Popu = (EditText)findViewById(R.id.editText_Popu);
            ////////////////////
      
            ////////2///////////
      Bundle bunde = this.getIntent().getExtras();
      //String strs = bunde.getString("key3").toString();
      Text_Popu.setText(bunde.getString("key3").toString());
            ////////////////////
      
     }
     
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.popu__tc, menu);
      return true;
     }

     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
       return true;
      }
      return super.onOptionsItemSelected(item);
     }
    }


    ///////////////////////////////////////////////////////////////////////////////////////////

    package com.example.test1;

    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;

    ////////////////////
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    import android.content.Intent;
    ////////////////////

    public class MainActivity extends ActionBarActivity {
     
        ////////////////////
     private Button myButton;
     private EditText myText;
     
     private Button myButton01;
     private Button myButton02;
        ////////////////////

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
           
            //////////1/////////
            myButton = (Button)findViewById(R.id.button1);
            myText = (EditText)findViewById(R.id.editText1);
           
            myButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    myText.setText("弄明白监听!");
                }
            });

            ////////////////////
           
           
            /////////2//////////
            myButton01 = (Button)findViewById(R.id.Button01);
            myButton01.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    ////显示文本------- 测试通过
                    //myText.setText("弄明白监听2!");

                 ////intent负责程序跳转和传递数据
                    //Intent intent = new Intent(this,F1_TC.class);
                    //startActivity(intent);
                    //Toast.makeText(this, "Toast", Toast.LENGTH_SHORT).show();
                 
                 Intent intent = new Intent(MainActivity.this, F1_TC.class);
                 startActivity(intent);
                 
                 
                 ////打开一个伪窗口------- 测试通过
                 //Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",
                 //Toast.LENGTH_SHORT).show();

                }
            });
            ////////////////////
           
            /////////3//////////
            myButton02 = (Button)findViewById(R.id.Button02);
            myButton02.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                 ////intent负责程序跳转和传递数据
                    Intent intent = new Intent(MainActivity.this,Popu_TC.class);
                   
                    Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
                    bundle.putString("key1", "value1"); // key1为名,value1为值
                    bundle.putString("key2", myButton02.toString());
                    bundle.putString("key3", myText.getText().toString());
                    bundle.putInt("keyInt1", 100);  //整数类型
                    intent.putExtras(bundle); // 传数据
                   
                   
                    startActivity(intent);   // ------- 测试通过    //不需要子窗口回传数据
                    //startActivityForResult(intent, 1); //requestCode是子窗口的id标志,而且必须大于1,否则回调函数onActivityResult不响应! 

                }
            });
            ////////////////////
           
           
        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
         
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
       
      
       

    }


     

  • 相关阅读:
    准备改进回复功能
    今天的任务
    日历已加上
    web.config中globalization设置的问题
    Request获取url信息的各种方法比较
    增加了高级评论功能
    如何修改日历的CSS
    推荐有关MasterPages的三篇文章
    如何定制日历控件显示的星期文字
    FreeTextBox的问题终于解决了
  • 原文地址:https://www.cnblogs.com/hutie1980/p/4545997.html
Copyright © 2020-2023  润新知