最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中Activity跳轉(zhuǎn)的創(chuàng)建步驟總結(jié)

 更新時(shí)間:2014年10月22日 08:57:18   作者:yuxikuo_1  
這篇文章主要介紹了Android中Activity跳轉(zhuǎn)的創(chuàng)建步驟總結(jié),本文詳細(xì)的講解了從工程創(chuàng)建到跳轉(zhuǎn)Activity的實(shí)現(xiàn)完整過程,需要的朋友可以參考下

一、創(chuàng)建工程

file->new->android application依次填入應(yīng)用名稱、工程名、包名
在工程目錄下找到src/com.example.helloworld MainActivity.java

二、添加代碼

復(fù)制代碼 代碼如下:

package com.example.helloworld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends Activity
{
    private Button button;
 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
     this.button = (Button) this.findViewById(R.id.button1);
         this.button.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent = new Intent();
                 intent.setClass(MainActivity.this, IntentActivity.class);
                 intent.putExtra("name", "Hello World");
                 startActivity(intent);
             }
         }); 
 } 
}

在添加代碼之前,先在res/layout/activity_main.xml中,拖拽一個(gè)Button控件上去。此時(shí)會(huì)自動(dòng)在activity_main.xml中生成Button的信息,注意id值,如果使用此Button,有用

三、添加跳轉(zhuǎn)Activity

1、右擊src/com.example.helloworld,new->class,在name處填寫IntentActivity,不用加java即可
2、添加layout。在res/layout處右擊,new->android XML file,在此xml上拖拽一個(gè)TextView上去。此時(shí)在R.java中自動(dòng)添加了TextView的地址
3、在AndroidManifest.xml中添加如下代碼:完成Activity的注冊(cè)

復(fù)制代碼 代碼如下:

<activity
   android:name="com.example.helloworld.IntentActivity"> </activity>

三、實(shí)現(xiàn)IntentActivity.java

復(fù)制代碼 代碼如下:

package com.example.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.content.Intent;
public class IntentActivity extends Activity
{
 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_intent);
  Intent intent = getIntent();
  String string = intent.getStringExtra("name");

  TextView textView = new TextView(this);
  textView.setTextSize(40);
  textView.setText(string);
  
  setContentView(textView);
 }
}

四、運(yùn)行

打開模擬器或者手機(jī),運(yùn)行。

相關(guān)文章

最新評(píng)論

桃源县| 随州市| 福海县| 文安县| 普兰店市| 长沙市| 华池县| 福贡县| 荥经县| 滁州市| 滨海县| 凌海市| 万荣县| 精河县| 台前县| 鄱阳县| 普兰店市| 太白县| 绿春县| 昭通市| 永修县| 濉溪县| 江门市| 石首市| 林西县| 临夏县| 县级市| 桃源县| 克东县| 民丰县| 洛南县| 孝昌县| 梧州市| 长沙县| 迁西县| 长阳| 峨边| 灵川县| 岳阳县| 梧州市| 巫溪县|