HelloAndroidUpDate

来源:互联网 发布:ican3官方软件下载 编辑:程序博客网 时间:2024/05/21 11:36
改善:
MainActivity类
<span style="font-family:KaiTi_GB2312;font-size:18px;">package cn.com.bztc.wf.androidupdate;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;   public class MainActivity extends Activity {public static final String TAG="MainActivity";private EditText etName;    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);              etName=(EditText) findViewById(R.id.etName);    }   public void sayHello(View view){    String name = etName.getText().toString();Intent intent = new Intent();intent.setClass(this,ShowActivity.class);/*Bundle bundle = new Bundle();bundle.putString("name",name);bundle.putInt("age",20);intent.putExtras(bundle);*/intent.putExtra("name",name);intent.putExtra("age",19);startActivity(intent);finish();    }}</span><span style="font-size:32px;"></span>

ShowActivity类
<span style="font-family:KaiTi_GB2312;font-size:18px;">package cn.com.bztc.wf.androidupdate;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ShowActivity extends Activity{private TextView tvShow;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_show);Bundle bundle = getIntent().getExtras();String name = bundle.getString("name");int age = bundle.getInt("age");initViews();tvShow.setText("你好"+name+"\n"+"你今年"+age+"岁");}private void initViews() {tvShow = (TextView) findViewById(R.id.tvShow);}}</span>
<span style="font-size:32px;">届时多了一个跳转页面命名为show</span>
<pre name="code" class="html"><span style="font-family:KaiTi_GB2312;font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@android:color/darker_gray"    android:gravity="center"    android:orientation="vertical" >    <TextView        android:id="@+id/tvShow"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Large Text"        android:textAppearance="?android:attr/textAppearanceLarge" /></LinearLayout></span>

运行时界面




0 0