Android的Eclipse是如何启动的按钮,点击一个新的活动 [英] Android eclipse how to start a new activity on button click
本文介绍了Android的Eclipse是如何启动的按钮,点击一个新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让这个当用户presses上的默认行为的一个按钮,它会打开一个新的活动。
I am trying to make it so that when the user presses a button on the default activity, it opens a new activity.
下面就是我的本钱。
在$ C $下按钮:
android:onClick="openmenu"
在code为openmenu的方法:
The code for the "openmenu" method:
public void openmenu(View view) {
Intent intent = new Intent(this , MainMenuPassed.class);
startActivity(intent);
}
干杯家伙!
推荐答案
您可以做的解决方法,如:
You can do workaround like :
定义一个ID为你的XML布局按钮
Define an Id for your button in xml layout
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Text"
/>
现在在你的活动课
public class MyActivity extends Activity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
final Button button =(Button) findVieById(R.id.button);
button.setOnClickListener(this);
}
@Override
protected void onClick(View view) {
switch(v.getId){
case R.id.button :
Intent intent = new Intent(this , MainMenuPassed.class);
startActivity(intent);
break;
}
}
}
这篇关于Android的Eclipse是如何启动的按钮,点击一个新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文