2011-09-08 137 views
1

我已经为我的应用程序添加了一项新活动,该活动已经进行了一些其他活动。我试图将我的新活动作为主要活动。当单击按钮时,应该调用先前存在的活动。按钮点击没有任何活动

我的问题是当我点击按钮没有活动执行。

我也对manifest文件进行了更改。

我的第一个目的已经

login = (Button) findViewById(R.id.login); 
login.setOnClickListener(new OnClickListener() { 

    public void onClick(View arg0) { 
     // TODO Auto-generated method stub 

     if(userName.equals("admin")&&password.equals("admin")){ 
      Toast.makeText(getApplicationContext(), "Invalid UserName or Password", Toast.LENGTH_LONG); 
      Intent main = new Intent(getApplicationContext(), OpenNMS.class); 
      startActivity(main); 
     } else { 
      Toast.makeText(getApplicationContext(), "Invalid UserName or Password", Toast.LENGTH_LONG); 
     } 
    } 
}); 

我的清单文件是

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.opennms.android" 
    android:versionCode="1" 
    android:versionName="1.0"> 

    <uses-sdk android:minSdkVersion="8" /> 

    <uses-permission android:name="android.permission.INTERNET"></uses-permission> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".Login" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".OpenNMS" android:label="@string/app_name"> 
     </activity> 
    </application> 
</manifest> 
+0

您确定要开始活动的条件为真?你有真正和错误的情况下相同的吐司。 –

+0

它是否进入'onClick'? – Ronnie

回答

1

在你的代码还没有添加show()到吐司消息,

Toast.makeText(getApplicationContext(), "Invalid UserName or Password", Toast.LENGTH_LONG); 

它应该是像这样

Toast.makeText(getApplicationContext(), "Invalid UserName or Password", Toast.LENGTH_LONG).show(); 

所以,它可能会在你不能看到吐司的其他部分。

谢谢。 Suri Sahani。

+0

我说得对,它会进入其他部分。我只使用记录器来发现用户名和密码字段是空的。但为什么会发生这种情况 – TechnocraT

+0

因此,你将不得不告诉我完整的代码,你如何检查管理员的详细信息。 –

+0

如果您将“Admin”作为用户名或密码,请使用equalsIgnoreCase代替等于的值。 –

0

试试这个:

login = (Button) findViewById(R.id.login); 
login.setOnClickListener(new View.OnClickListener() { 

    public void onClick(View arg0) { 
     // TODO Auto-generated method stub 

     if(userName.equals("admin")&&password.equals("admin")){ 
      Toast.makeText(getApplicationContext(), "Invalid UserName or Password", Toast.LENGTH_LONG).show(); 
      Intent main = new Intent(getBaseContext(), OpenNMS.class); 
      startActivity(main); 
     } else { 
      Toast.makeText(getBaseContext(), "Invalid UserName or Password", Toast.LENGTH_LONG).show(); 
     } 
    } 
}); 

你错过view

login.setOnClickListener(new OnClickListener() { 

login.setOnClickListener(new View.OnClickListener() { 
0

改变这一行

Intent main = new Intent(getApplicationContext(), OpenNMS.class); 

Intent main = new Intent(Login.this, OpenNMS.class); 

,看看它是否工作。