Wie starten Sie eine andere Tätigkeit mit Knopf im Fragment

Möchte ich öffnen Sie eine andere Aktivität aus-Fragment-Taste, aber jedes mal, wenn ich die app starte, werde ich leider Aufhören.

Ich habe dies seit einer Woche immer noch nicht ausführen können, die Tasten. Ich werde dankbar, wenn jemand gab mir die Antwort. Ich bin neu hier im android.

Mein code ist über die Seite Menü dann einer von der Seite Menü enthält Schaltflächen zum öffnen einer neuen Aktivität

package tipqc.softeng.sundroidtracker;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class FindPeopleFragment extends Fragment{


View view;

//Intent i;

public FindPeopleFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    final View view = inflater.inflate(R.layout.fragment_find_people, container, false);

    Button button = (Button)view.findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v){
            switch(v.getId()){

            case R.id.button1:
            Intent intent1 = new Intent(view.getContext(), ResearchStudy.class);
                startActivity(intent1);
                break;
            }
            //startActivity(i);
        }
    });

    return view;
}
}

Unten ist log

12-31 14:36:33.040: E/AndroidRuntime(2843): FATAL EXCEPTION: main
12-31 14:36:33.040: E/AndroidRuntime(2843): Process: tipqc.softeng.sundroidtracker, PID: 2843
12-31 14:36:33.040: E/AndroidRuntime(2843): java.lang.RuntimeException: Unable to start activity ComponentInfo{tipqc.softeng.sundroidtracker/tipqc.softeng.sundroidtracker.ResearchStudy}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.os.Handler.dispatchMessage(Handler.java:102)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.os.Looper.loop(Looper.java:135)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.ActivityThread.main(ActivityThread.java:5221)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at java.lang.reflect.Method.invoke(Native Method)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at java.lang.reflect.Method.invoke(Method.java:372)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-31 14:36:33.040: E/AndroidRuntime(2843): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at tipqc.softeng.sundroidtracker.ResearchStudy.onCreate(ResearchStudy.java:12)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.Activity.performCreate(Activity.java:5933)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-31 14:36:33.040: E/AndroidRuntime(2843):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-31 14:36:33.040: E/AndroidRuntime(2843):     ... 10 more
  • Ersetzen getActivity().startActivity(intent1); durch startActivity(intent1); und versuchen Sie es erneut.
  • Add log hier...
  • Dein code scheint ok. Zeigen Sie Ihre logcat.
  • noch ist es leider beenden..
  • Siehe meine Antwort unter @IsaacRoldanMoton
  • noch gab mir 12-31 14:36:33.040: E/AndroidRuntime(2843): java.lang.RuntimeException: Unable to start activity ComponentInfo{tipqc.softeng.sundroidtracker/tipqc.softeng.sundroidtracker.ResearchStudy}: java.lang.IllegalStateException: Sie brauchen, um ein Thema zu verwenden.AppCompat Thema (oder Nachkomme) mit dieser Tätigkeit.
  • Ich merke, wenn ich die ResearchStudy.class zu MainActivity.class .. es funktioniert, warum researchstudy nicht funktionieren

InformationsquelleAutor Zach | 2014-12-31
Schreibe einen Kommentar