5 回答
TA贡献1828条经验 获得超3个赞
在您的点击侦听器中编写此代码:
btn_right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
current_image_index++;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
});
TA贡献1815条经验 获得超6个赞
你必须开始你的第二个活动
startActivity(new Intent(getApplicationContext(), MainActivity.class));
确保您在清单文件中添加了第二个活动
TA贡献1111条经验 获得超0个赞
没有代码可以导航到 MainActivity
触发以下代码
private void startMainActivity(){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
TA贡献1821条经验 获得超4个赞
void SwitchButton() {
btn_right = (Button) findViewById(R.id.btn_right);
btn_left = (Button) findViewById(R.id.btn_left);
btn_right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
current_image_index++;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
startMainPage();
}
});
btn_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
current_image_index--;
if (current_image_index < 0) {
current_image_index = images.length - 1;
}
imageView.setImageResource(images[current_image_index]);
startMainPage();
}
}
);
}
private void startMainPage() {
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
}
TA贡献1804条经验 获得超3个赞
无论您想在哪里调用下一个活动,请使用:-
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
添加回答
举报