簡體   English   中英

單擊按鈕時未執行任何活動

[英]no activity performed on button click

我向應用程序添加了一個新活動,該活動已經具有其他活動。 我正在嘗試將新活動作為主要活動。單擊按鈕時,應調用以前存在的活動。

我的問題是,當我單擊按鈕時未執行任何活動。

我也在清單文件中進行了更改。

我的初衷是

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>

在您的代碼中,您尚未向Toast消息中添加show()

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

應該是這樣

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

因此,可能是在您無法看到Toast的其他部分進行的。

謝謝。 蘇里·薩哈尼(Suri Sahani)。

嘗試這個 :

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() {

更改此行

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

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

看看是否可行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM