求一段单击按钮,从一个界面跳转到另一个界面的android的代码
1个回答
展开全部
您好,是这样的:
package ui.one.test;
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 Ui3Activity extends Activity {
private Button button1;
private Button button2;
private Button button3;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取控件
button1 = (Button)this.findViewById(R.id.button1);
button2 = (Button)this.findViewById(R.id.button2);
button3 = (Button)this.findViewById(R.id.button3);
//注册点击事件
button1.setOnClickListener(listener);
button2.setOnClickListener(listener);
button3.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener()
{
public void onClick(View view)
{
// TODO Auto-generated method stub
Button button = (Button) view;//强制转换类型
switch (button.getId())
{
case R.id.button1: {
Intent intent = new Intent();
intent.setClass(Ui3Activity.this, Ui3son1Activity.class);
startActivity(intent);
}break;
case R.id.button2: {
Intent intent = new Intent();
intent.setClass(Ui3Activity.this, Ui3son2Activity.class);
startActivity(intent);
}break;
case R.id.button3: {
Intent intent = new Intent();
intent.setClass(Ui3Activity.this, Ui3son2Activity.class);
startActivity(intent);
}break;
}
}
};
}
package ui.one.test;
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 Ui3Activity extends Activity {
private Button button1;
private Button button2;
private Button button3;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取控件
button1 = (Button)this.findViewById(R.id.button1);
button2 = (Button)this.findViewById(R.id.button2);
button3 = (Button)this.findViewById(R.id.button3);
//注册点击事件
button1.setOnClickListener(listener);
button2.setOnClickListener(listener);
button3.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener()
{
public void onClick(View view)
{
// TODO Auto-generated method stub
Button button = (Button) view;//强制转换类型
switch (button.getId())
{
case R.id.button1: {
Intent intent = new Intent();
intent.setClass(Ui3Activity.this, Ui3son1Activity.class);
startActivity(intent);
}break;
case R.id.button2: {
Intent intent = new Intent();
intent.setClass(Ui3Activity.this, Ui3son2Activity.class);
startActivity(intent);
}break;
case R.id.button3: {
Intent intent = new Intent();
intent.setClass(Ui3Activity.this, Ui3son2Activity.class);
startActivity(intent);
}break;
}
}
};
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询