如何做多意图? [英] How to do multiple intents?
问题描述
我试图做3意图开始一个新的活动, 然而,我发现,我总是得到一个错误。 我把我的code到main.java code:
公共类主要扩展活动{
巴顿服务;
按钮库;
按键接触;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
服务=(按钮)findViewById(R.id.Services);
service.setOnClickListener(新View.OnClickListener(){
});
画廊=(按钮)findViewById(R.id.Gallery);
gallery.setOnClickListener(新View.OnClickListener(){
});
接触=(按钮)findViewById(R.id.Contact);
contact.setOnClickListener(新View.OnClickListener(){
});
公共无效的onClick(视图v){
//充气菜单;这增加了项目操作栏,如果它是present。
意向意图=新的意图(Main.this,servicesActivity.class);
startActivity(意向);
}
公共无效onClick1(视图v){
意图intent1 =新的意图(Main.this,galleryActivity.class);
startActivity(intent1);
}
公共无效onClick2(视图v){
意图intent2 =新的意图(Main.this,contactActivity.class);
startActivity(intent2);
}
}
}
我已经尝试了不同的方法,甚至把括号在不同的地方。我也一直在寻找互联网周,没有发现任何与超过1工作。 我上的的OnClick和新View.OnClickListener()的得到错误。 我有一个工作这就是为什么我尝试了同样的code有3个按钮。 基本上我对主activity.xml 3个按键。所有我想要做的是:
>按钮1>云>活动1'
>按钮2>云>活性2
>按钮3>云> activity3
请给我任何提示或技巧,因为我是新来的Android开发人员。
公共类主要扩展活动{
巴顿服务;
按钮库;
按键接触;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
服务=(按钮)findViewById(R.id.Services);
service.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v)
{
意向意图=新的意图(Main.this,servicesActivity.class);
startActivity(意向);
}
});
画廊=(按钮)findViewById(R.id.Gallery);
gallery.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v)
{
意图intent1 =新的意图(Main.this,galleryActivity.class);
startActivity(intent1);
}
});
接触=(按钮)findViewById(R.id.Contact);
contact.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v)
{
意图intent2 =新的意图(Main.this,contactActivity.class);
startActivity(intent2);
}
});
}
I'm trying to do 3 intents to start a new activity, however I find that I always get an error. I'm putting my code onto main.java code:
public class Main extends Activity {
Button service;
Button gallery;
Button contact;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
service = (Button)findViewById(R.id.Services);
service.setOnClickListener(new View.OnClickListener() {
});
gallery = (Button)findViewById(R.id.Gallery);
gallery.setOnClickListener(new View.OnClickListener() {
});
contact = (Button)findViewById(R.id.Contact);
contact.setOnClickListener(new View.OnClickListener() {
});
public void onClick (View v) {
// Inflate the menu; this adds items to the action bar if it is present.
Intent intent = new Intent (Main.this, servicesActivity.class);
startActivity(intent);
}
public void onClick1 (View v) {
Intent intent1 = new Intent (Main.this, galleryActivity.class);
startActivity(intent1);
}
public void onClick2 (View v) {
Intent intent2 = new Intent (Main.this, contactActivity.class);
startActivity(intent2);
}
}
}
I have tried different ways and even putting brackets in different places. also I have been searching on the internet for weeks and found nothing that work with more than 1. I'm getting errors on OnClick and new View.OnClickListener(). I have got one working which is why I tried the same code with 3 buttons. Basically I have 3 buttons on main activity.xml. All I want to do is:
>'button1 >goes> activity1'
>'button2 >goes> activity2'
>'button3 >goes> activity3'
Please give me any hints or tips as I'm new to Android dev.
public class Main extends Activity {
Button service;
Button gallery;
Button contact;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
service = (Button)findViewById(R.id.Services);
service.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent intent = new Intent (Main.this, servicesActivity.class);
startActivity(intent);
}
});
gallery = (Button)findViewById(R.id.Gallery);
gallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent intent1 = new Intent (Main.this, galleryActivity.class);
startActivity(intent1);
}
});
contact = (Button)findViewById(R.id.Contact);
contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent intent2 = new Intent (Main.this, contactActivity.class);
startActivity(intent2);
}
});
}
这篇关于如何做多意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!