Wo liegt der Fehler?


Javandroid

Grünschnabel
Hallo zusammen,

untenstehend meine Test-App.

Mein Plan ist es ein Login zu programmieren.

Die Benutzeroberfläche habe Ich bereits aber iwie reagieren die Buttons in Register und in MainActivity nicht. Warum?

Wie teile Ich dem Programm mit, dass nun auf Eingaben in einer anderen View reagiert werden soll?

Hier mein Code:

SplashScreen.java:
Code:
package de.test.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity {

	private static final int SPLASH_TIME = 2 * 1000;// 3 seconds

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splashscreen);

		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {

				Intent intent = new Intent(SplashScreen.this,
						MainActivity.class);
				startActivity(intent);

				SplashScreen.this.finish();

				overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

			}
		}, SPLASH_TIME);
		
		new Handler().postDelayed(new Runnable() {
			  @Override
			  public void run() {
			         } 
			    }, SPLASH_TIME);

	}

	
	@Override
	public void onBackPressed() {
		this.finish();
		super.onBackPressed();
	}
}
Manifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.test.test"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".SplashScreen"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       <activity android:name=".MainActivity"></activity>
       <activity android:name=".Register"></activity>
    </application>

</manifest>
MainActivity:
Code:
package de.test.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	Button btnClick;
	String password;
	String email;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnClick=(Button)findViewById(R.id.btnLogin);
        btnClick=(Button)findViewById(R.id.btnLinkToRegisterScreen);
        
        btnClick.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View w) {
				switch(w.getId()){
				case R.id.btnLogin:
					Toast.makeText(MainActivity.this, "Clicked Login", Toast.LENGTH_LONG).show();
					email = (String) getText(R.id.loginEmail);
					password =  (String) getText(R.id.loginPassword);
					break;
				case R.id.btnLinkToRegisterScreen:
					//Toast.makeText(MainActivity.this, "Clicked Register", Toast.LENGTH_LONG).show();
					setContentView(R.layout.register);
					break;
				}
			
			}
		});
    }
}
Register.java:
Code:
package de.test.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Register extends Activity {
	
	Button btnClick;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        
        btnClick=(Button)findViewById(R.id.btnRegister);
        btnClick=(Button)findViewById(R.id.btnLinkToLoginScreen);
        
        btnClick.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View w) {
				switch(w.getId()){
				case R.id.btnLogin:
					Toast.makeText(Register.this, "Clicked Login", Toast.LENGTH_LONG).show();
					break;
				case R.id.btnLinkToRegisterScreen:
					Toast.makeText(Register.this, "Clicked Register", Toast.LENGTH_LONG).show();
					setContentView(R.layout.main);
					break;
				}
			
			}
		});
    }
}
 
Zuletzt bearbeitet:

Fasibio

Mitglied
Hallo,
zwei sachen.
1. Schau dir Intent an und lerne damit zu arbeiten .... (das löst dein Problem)
2. innere Anonyme Klassen sind böse!
 
Zuletzt bearbeitet: