Android 多个onclick侦听器修复
我试图在一个活动中包含10个图像按钮,我希望在这一个活动中单击所有按钮。我有我认为适合我需要的代码,但我遇到的问题是..在我的java代码中,我看不到打开新活动的意图Android 多个onclick侦听器修复,android,android-intent,Android,Android Intent,我试图在一个活动中包含10个图像按钮,我希望在这一个活动中单击所有按钮。我有我认为适合我需要的代码,但我遇到的问题是..在我的java代码中,我看不到打开新活动的意图 package com.baha.beallhasall; import android.app.Activity; import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle;
package com.baha.beallhasall;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class FirstActivityPage extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_one);
ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton1);
ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
ImageButton btn3 = (ImageButton)findViewById(R.id.imageButton3);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.imageButton1:
break; // intent ?????//
case R.id.imageButton2:
break;
case R.id.imageButton3:
break;
}
}
}
所以点击图像按钮1是可以的,但点击后什么也没发生。
我是否需要在某个地方实现并意图打开它。我现在不知所措
像这样的东西不见了
Intent myIntent = new Intent(view.getContext(), FourActivityPage.class);
startActivityForResult(myIntent, 0);
谢谢您应该实现您所说的它缺少的内容 根据单击的图像(您的
切换案例
语句),您应该声明一个意图
并启动它
Intent intent = new Intent(FirstActivityPage.this, SecondActivityPage.class);
startActivity(intent);
您想要实现什么?首先,您不需要实现onClickListener或从Java代码调用setOnClickListener();在XML文件中,对于每个按钮属性,您应该能够添加android:onClick=“onClick”,它将在活动中自动调用onClick方法。您设置该方法和switch语句的方式是正确的。您所要做的就是将发布的Intent和startActivity()代码放入case语句中,以获得所需的内容。如果有人遇到这段代码,这会让我更容易。。