Ich kann nicht von einer Seite zur nächsten wechseln.
Die Taste funktioniert nicht, wenn ich drücke, passiert nichts.
Können Sie erklären warum?
Ich möchte einfach auf Seite activity_main.xml
zu pagetwo.xml
gehen, und um es zu tun, versuche ich Activity
zu ändern.So ändern Sie die aktuelle Seite und wechseln von activity_main.xml zu pagetwo.xml
Meine Seiten:
MainActivity:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
}
}
class open extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent("call");
startActivity(i);
}
});
}
}
Aufruf:
public class call extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pagetwo);
}
}
Manifest:
...
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".call"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter >
<action android:name="android.intent.action.PICK_ACTIVITY"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
pagetwo:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Finally"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>
activity_main:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_marginTop="6dp"
android:layout_centerHorizontal="true"
android:text="page two" />
</RelativeLayout>
Bye!
https://developer.android.com/training/basics/firstapp/starting-activity.html – tachyonflux
Ihr Code ist viel zu kompliziert und zeigt, dass Sie Aktivitäten nicht verstehen (Sie sollten nicht mehr als 2 hier haben und sollten nicht Aktivität und AppCompatActivity mischen). Ich schlage vor, Tutorials und Dokumente zu lesen und Ihnen den Code zu geben, der Ihnen schadet. –
danke, ich lese alles und jetzt habe ich mein Problem gelöst. – User