android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按Action值1启动目标Activity" /> android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_conten" />
您现在的位置:首页 > >

android 多个 intentfilter,android之隐示意图--在一个 意图中用两个action启动这个activity...

发布时间:

主页面布局:layout/activity_main.xml



android:layout_width="match_parent"


android:layout_height="match_parent"


android:orientation="vertical">



android:id="@+id/btn1"


android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:text="按Action值1启动目标Activity" />



android:id="@+id/btn2"


android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:text="按Action值2启动目标Activity" />


主页面java代码:


package com.sxt.day04_07_twoaction;


import android.os.Bundle;


import android.app.Activity;


import android.content.Intent;


import android.view.Menu;


import android.view.View;


import android.view.View.OnClickListener;


public class MainActivity extends Activity implements OnClickListener{


@Override


protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);


setListener();


}


private void setListener() {


findViewById(R.id.btn1).setOnClickListener(this);


findViewById(R.id.btn2).setOnClickListener(this);


}


@Override


public void onClick(View v) {


Intent intent=new Intent();


switch (v.getId()) {


case R.id.btn1:


intent.setAction("com.sxt.day04_07_twoaction.SecondActivity");


break;


case R.id.btn2:


intent.setAction("com.sxt.day04_07_twoaction.SecondActivity2");


break;


}


startActivity(intent);


}


}


第二个页面布局:layout/activity_second.xml



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=".SecondActivity" >



android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:text="@string/hello_world" />


第二个页面java代码:


package com.sxt.day04_07_twoaction;


import android.os.Bundle;


import android.app.Activity;


import android.util.Log;


import android.view.Menu;


public class SecondActivity extends Activity {


@Override


protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);


setContentView(R.layout.activity_second);


Log.i("main","SecondActivity");


}


}


列表清单:AndroidManifest.xml



package="com.sxt.day04_07_twoaction"


android:versionCode="1"


android:versionName="1.0" >



android:minSdkVersion="8"


android:targetSdkVersion="18" />



android:allowBackup="true"


android:icon="@drawable/ic_launcher"


android:label="@string/app_name"


android:theme="@style/AppTheme" >



android:name="com.sxt.day04_07_twoaction.MainActivity"


android:label="@string/app_name" >



android:name="com.sxt.day04_07_twoaction.SecondActivity"


android:label="@string/title_activity_second" >


效果:









相关资源:根据三相电流计算正序负序零序的软件


热文推荐
猜你喜欢
友情链接: