2016-12-18 5 views
0

Ich weiß, dass dies einfach scheint, und ich habe versucht, alles in anderen Threads erwähnt, aber aus irgendeinem Grund funktioniert es nicht.Schaltfläche zum Öffnen einer anderen Aktivität

Ich möchte einfach die Schaltfläche auf der phind.xml die activity_alerts.xml öffnen und umgekehrt, aber aus irgendeinem Grund funktioniert es nicht. Ich denke, ich vermisse etwas Einfaches.

phind.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" 
    android:id="@+id/phind" 
    android:background="#ff0000"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Alert Message!" 
     android:gravity="center" 
     android:textSize="36sp" 
     android:textColor="@color/black" 
     android:layout_weight="1"/> 

    <Button 
     android:id="@+id/disable" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Disable alert"/> 

</LinearLayout> 

Phind.java:

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 

import com.phinder.phinder.R; 

public class Phind extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.phind); 

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

      @Override 
      public void onClick(View v) { 

       Intent i = new Intent(getApplicationContext(),ActivityAlerts.class); 
       startActivity(i); 
      } 

     }); 
    } 
} 

activity_alerts.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/light_gray" 
     android:orientation="vertical" 
     tools:context="com.phinder.phinder.Menu.Alerts"> 


     <Button 
      android:id="@+id/test" 
      android:layout_height="wrap_content" 
      android:text="test your alert" 
      android:height="24dp" 
      android:layout_width="match_parent"/> 

    </LinearLayout> 

ActivityAlerts.java:

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 

import com.phinder.phinder.R; 

public class ActivityAlerts extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_alerts); 

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

      @Override 
      public void onClick(View v) { 

       Intent i = new Intent(getApplicationContext(),Phind.class); 
       startActivity(i); 
      } 

     }); 
    } 
} 

Manifest:

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

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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

     <meta-data 
      android:name="com.facebook.sdk.ApplicationId" 
      android:value="@string/app_id" /> 

     <activity android:name=".LoginActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <activity 
      android:name=".MainActivity" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity 
      android:name=".Menu.About" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity 
      android:name=".Menu.Alerts" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="stateHidden" /> 
     <activity 
      android:name=".Menu.Pin" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="stateHidden" /> 
     <activity 
      android:name=".Menu.Help" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity 
      android:name=".Phind" 
      android:label="@string/app_name" /> 
     <activity 
      android:name=".ActivityAlerts" 
      android:label="@string/app_name"/> 

     <activity 
      android:name="com.facebook.FacebookActivity" 
      android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Translucent.NoTitleBar" /> 
    </application> 

</manifest> 

ich einen Teil des überschüssigen Code in der activity_alerts.xml entfernt, um es einfacher die Taste

Logcat finden ab, wenn ich die activity_alerts.xml öffnen und endend bei, wenn ich klicken Sie auf die Schaltfläche, die mich an die phind.xml nehmen sollte (nichts danach passiert, so der Bericht endet):

12-18 15:03:10.704 9207-9207/com.phinder.phinder I/Timeline: Timeline: Activity_launch_request id:com.phinder.phinder time:53000744 
12-18 15:03:10.749 9207-9207/com.phinder.phinder D/ViewRootImpl: #3 mView = null 
12-18 15:03:10.799 9207-9207/com.phinder.phinder D/SecWifiDisplayUtil: Metadata value : none 
12-18 15:03:10.799 9207-9207/com.phinder.phinder D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{e76390 I.E...... R.....ID 0,0-0,0} 
12-18 15:03:10.824 9207-9261/com.phinder.phinder D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1 
12-18 15:03:10.839 9207-9207/com.phinder.phinder W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView) 
12-18 15:03:10.854 9207-9207/com.phinder.phinder D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1 
12-18 15:03:10.884 9207-9207/com.phinder.phinder I/Timeline: Timeline: Activity_idle id: [email protected] time:53000921 
12-18 15:03:10.904 9207-9207/com.phinder.phinder V/ActivityThread: updateVisibility : ActivityRecord{e144243 [email protected] {com.phinder.phinder/com.phinder.phinder.MainActivity}} show : false 
12-18 15:03:13.769 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
12-18 15:03:13.769 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
12-18 15:03:14.379 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
12-18 15:03:14.379 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
12-18 15:03:16.799 9207-9207/com.phinder.phinder D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
12-18 15:03:16.909 9207-9207/com.phinder.phinder D/ViewRootImpl: ViewPostImeInputStage processPointer 1 

Antwort

0

Versuchen Sie, Ihre Absicht ändern: in Phind.java

Intent i = new Intent(ActivityAlerts.this, Phind.class); 
ActivityAlerts.this.startActivity(i); 
finish(); 

auch Ihre Aktivität in menifest erklären:

<activity android:name=".ActivityAlerts" android:label="@string/app_name"> 
</activity> 

In phind.xml Verwendung

tools:context=".Phind" 

und In activity_alerts.xml Verwendung

tools:context=".ActivityAlerts" 
+0

noch keine Maßnahmen ergriffen werden, wenn ich drücke den Knopf :( –

+0

kannst du dein Manifest zeigen ...? – rafsanahmad007

+0

Ich habe es zu der ursprünglichen Frage für Sie hinzugefügt –

Verwandte Themen