开发者

no activity performed on button click

I have added a new activity to my application which already had some other activities. I am trying to make my new activity as main activity.when a button is clicked the previously existing activities should be called.

My problem is when i click the button no activity is performed.

I have made changes in manifest file as well.

My first intent has

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);
        }
    }
});

my manifest file is

<?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>
                <acti开发者_开发知识库on 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>


In your code you haven't added show() to the Toast message,

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

It should be like this

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

So, it might be going in your else part where you are not able to see the Toast.

Thanks. Suri Sahani.


Change this line

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

to

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

and see if it works.


try this :

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();
        }
    }
});

you have miss view

login.setOnClickListener(new OnClickListener() {  

to

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜