2017-04-10 7 views
0

Hallo ich bin neu bei Android und ich habe ein Problem mit mehreren Tasten zuerst Ich implementiert mehrere Taste in meiner MainActivity und es ist Arbeit mit mir jetzt ich eine andere Aktivität erstellen und implementieren das gleiche, was ich tun die mainActivity in der neuen Tätigkeit habe ich eine mehr Schaltfläche in dieser AktivitätonClick mehrere Taste - Android

die neue Aktivität (Activity6.class):

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.content.Intent; 
import android.view.View; 
import android.widget.Button; 
public class Activity6 extends AppCompatActivity implements 
View.OnClickListener{ 


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

    Button ee = (Button) findViewById(R.id.button12); 
    Button ff = (Button) findViewById(R.id.button9); 
    Button gg = (Button) findViewById(R.id.button10); 
    Button hh = (Button) findViewById(R.id.button11); 
    ee.setOnClickListener(this); 
    ff.setOnClickListener(this); 
    gg.setOnClickListener(this); 
    hh.setOnClickListener(this); 


} 
@Override 
public void onClick (View vv){ 

    switch (vv.getId()) { 

     case R.id.button12: 

      Intent e = new Intent(Activity6.this, Admin1.class); 
      startActivity(e); 


      break; 

     case R.id.button9: 

      Intent f = new Intent(Activity6.this, User1.class); 
      startActivity(f); 

      break; 

     case R.id.button10: 
      Intent g = new Intent(Activity6.this, Teacher1.class); 
      startActivity(g); 

      break; 

     case R.id.button11: 
      Intent h = new Intent(Activity6.this, Class1.class); 
      startActivity(h); 

      break; 


     default: 
      break; 
    } 

} 

Admin1.class

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 

public class Admin1 extends AppCompatActivity { 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.admin); 

} 
} 

User1.class

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 

public class User1 extends AppCompatActivity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.adminuser); 

} 
} 

Aktivität Teacher1.class und Class1.class haben das gleiche mit Admin1.class und User1.class aber mit unterschiedlichem Layout. Hinweis: Ich füge alle Aktivitäten in manifest wie folgt aus:

<activity android:name=".Activity6"></activity> 
    <activity android:name=".Admin1"></activity> 
    <activity android:name=".Class1"></activity> 
    <activity android:name=".Teacher1"></activity> 
    <activity android:name=".User1"></activity> 

adminbackdoor.XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<TextView 
    android:text="العمليات" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView" 
    android:fontFamily="serif" 
    android:textSize="30sp" 
    android:textStyle="bold" 
    android:layout_marginTop="60dp" 
    android:layout_marginRight="140dp" /> 

<Button 
    android:id="@+id/button12" 
    android:layout_width="231dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_marginTop="20dp" 
    android:background="@drawable/round" 
    android:text="admin" 
    android:textSize="24sp" 
    android:textStyle="bold" /> 

<Button 
    android:id="@+id/button9" 
    android:layout_width="231dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_marginTop="20dp" 
    android:background="@drawable/round" 
    android:text="user" 
    android:textSize="24sp" 
    android:textStyle="bold" /> 

<Button 
    android:id="@+id/button10" 
    android:layout_width="231dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_marginTop="20dp" 
    android:background="@drawable/round" 
    android:text="teacher" 
    android:textSize="24sp" 
    android:textStyle="bold" /> 

<Button 
    android:id="@+id/button11" 
    android:layout_width="231dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_marginTop="20dp" 
    android:background="@drawable/round" 
    android:text="class" 
    android:textSize="24sp" 
    android:textStyle="bold" /> 

    </LinearLayout> 

und onClick mit mir nicht funktioniert, weiß ich nicht, was das Problem ist ?? Wenn ich die Anwendung ausführen und auf die Schaltfläche klicken, funktionierten sie nicht (gehen Sie zu einem anderen Layout)

+2

was meinst du: 'und onClick funktioniert nicht mit me' –

+1

Sie müssen versuchen und seine etwas klarer, was das Problem ist, das Sie haben. Momentan ist Ihre Frage ziemlich unklar. – codeMagic

+0

Ich meine, wenn ich die Anwendung ausführen und klicken Sie auf die Schaltfläche haben sie nicht funktioniert (gehen Sie zu einem anderen Layout – reemsr

Antwort

-1

Zunächst sollten Sie Activity und nicht AppCompatActivity erweitern.

Und eine Sache, die ich empfehlen kann, ist die Click-Hörer wie dies in dieser Situation zu verwenden:

Button ee = (Button) findViewById(R.id.button12); 
     ee.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent e = new Intent(Activity6.this, Admin1.class); 
       startActivity(e); 
      } 
     }); 
+0

' AppCompatActivity' wird zur Unterstützung der Kompatibilität empfohlen –

+0

Ich kann den Klick-Listener verwenden, wie Sie tun, weil ich gewechselt habe – reemsr

Verwandte Themen