在android eclips中打开按钮单击事件的新页面 [英] Open new page on button's click event in android eclips

查看:99
本文介绍了在android eclips中打开按钮单击事件的新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击按钮的同时打开一个新的活动页面/窗口。

,例如当点击登录按钮时,个人资料页面打开。



我是怎么做到的?



我有搜索了它的代码。但我不知道如何给出新页面的路径?我搜索的代码是:



  public   MyActivity扩展活动{
受保护 void onCreate (捆绑冰柱){
super.onCreate(冰柱);

setContentView(R.layout.content_layout_id);

final按钮=(按钮)findViewById(R.id.button_id);
button.setOnClickListener( new View.OnClickListener(){
public void onClick(查看v){
// ? ????这里我想给出要打开的页面的路径......
}
});
}
}





如何给出新页面的路径?

提前致谢!

解决方案

将此代码放入您的onClick(){} ...它应该可以工作..如果没有,请告诉我。

  if (v.getId()== R.id.button_id)
{
Intent firstpage = new Intent( this ,yourPageName。 class );
startActivity(firstpage);
}


  public   MyActivity  extends 活动{
受保护 void onCreate(Bundle icicle){
super .onCreate(icicle);

setContentView(R.layout.content_layout_id);

final 按钮按钮=(按钮)findViewById(R.id.button_id);
button.setOnClickListener( new View.OnClickListener(){
public void onClick(查看v){
意图意图= 意图(MyActivity。 this ,YourActivity。 class );
startActivity(intent);
}
}) ;
}
}





并在展示文件中添加该活动


将意图放入

意图firstpage = new Intent( getApplicationContext(),yourPageName.class);

startActivity(firstpage);



不要忘记在清单中添加活动
< activity android:name = 。yourPageName.class / >


I want to open a new activity page/window while click on a button.
e.g. when click on a login button the profile page open.

How I do it?

I have searched a code for it. but I dnt know how do I give the path of new page ? The code I have searched is:

public class MyActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         final Button button = (Button) findViewById(R.id.button_id);
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // ????? here I want to give the path of the page to be opened...
             }
         });
     }
 }



how do I give the path of new page?
Thanks in advance!

解决方案

Put this code inside your onClick(){}...It should work..If not,let me know.

if(v.getId()==R.id.button_id)
{
    Intent firstpage=new Intent(this,yourPageName.class);
    startActivity(firstpage);
}


public class MyActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         final Button button = (Button) findViewById(R.id.button_id);
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 Intent intent = new Intent(MyActivity.this, YourActivity.class);
        startActivity(intent);
             }
         });
     }
 }



And Add that activity in manifeast file


Put Intent as
Intent firstpage=new Intent(getApplicationContext(),yourPageName.class);
startActivity(firstpage);

don't forget to add activity in manifest
<activity android:name=".yourPageName.class"/>


这篇关于在android eclips中打开按钮单击事件的新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆