2016-12-18 4 views
0

Я знаю, это может показаться простым, и я пробовал все упомянутое в других потоках, но по какой-то причине он не работает.Кнопка, чтобы открыть другое мероприятие

Я просто хочу кнопку на phind.xml, чтобы открыть activity_alerts.xml и наоборот, но по какой-то причине она не работает. Наверное, я пропустил что-то простое.

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> 

Я удалил часть избыточного кода в activity_alerts.xml, чтобы сделать его легче найти кнопку

Logcat, начиная с момента, когда я открываю activity_alerts.xml и заканчивая, когда я нажмите на кнопку, которая должна взять меня к phind.xml (ничего не происходит после этого, поэтому отчет заканчивается):

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 

ответ

0

Попробуйте изменить свое намерение: в Phind.java

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

также объявить вашу деятельность в menifest:

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

В phind.xml использования

tools:context=".Phind" 

и в использовании activity_alerts.xml

tools:context=".ActivityAlerts" 
+0

Еще никакие меры не принимаются, когда я нажмите кнопку :( –

+0

может показать свое проявление ...? – rafsanahmad007

+0

Я добавил его к исходному вопросу для вас –

Смежные вопросы