我想知道如果您可以使用按鈕單擊發送用戶到另一個.xml佈局沒有第二個.java類使用Intent intent = new Intent(this,layout_name.xml);?我可以只用MAinActvity.java類將用戶發送到另一個.xml嗎?
還是我必須製作另一個.java類才能使用Intent。
我用這個guide但它沒有看起來鍛鍊
MainActivity
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
/*
This app is for a local Vape Shop
it's purpose is to increase customer flow, and provide a menu for Android users
the array is going to be called = da_menu
*/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateListView();
}
public void sendMessage(View view) {
// once this button is clicked it wil send the user to the about us activity
Intent intent = new Intent(this, aboutus.xml);
}
private void populateListView() {
// Create the list of items
String[] juiceMenu= {
"#1 BlueBerry Bombshell",
"#2 Richie Rich",
"#3 Chiquita",
"#4 Afternoon Delight",
"#5 Poppin Otters",
"#6 Viva La Sangria",
"#7 Okole Maluna",
"#8 Carmen Miranda",
"#9 Pomalade",
"#10 Izual",
"#11 Butter Stotch",
"#12 Blue Bulls",
"#13 Grape Ape",
"#14 Bruce Juice",
"#15 Doc Holiday",
"#16 Peachy Keen",
"#17 Hula",
"#18 New York",
"#19 Al Gore",
"#20 Lux Charms",
"#21 Sailor Jack",
"#22 Get Him to the Greek",
"#23 Key We Lie Chi",
"#24 Spring Fling",
"#25 Gumby",
"#26 Chai-Milk",
"#27 Mr. Bean",
"#28 50 Shades of Orange",
"#29 Blue Waffles",
"#30 Enigma",
"#31 Mr. Freeze",
"#32 Cup of Joe"};
// Build adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, // context for the activity
R.layout.da_menu, // Layout to create
juiceMenu); // Items to be displayed
//configure list view
ListView list = (ListView) findViewById(R.id.listViewMain);
list.setAdapter(adapter);
}
}
activity_main.xml中 這是主要的頁面,並點擊的按鈕,我想聲明with android:id =「@ + id/buttonAboutUs」
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.vitoriano_vaz.eastbayvapes.MainActivity">
<TextView
android:textAllCaps="true"
android:textSize="22dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to East Bay Vapes"
android:id="@+id/textView" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listViewMain"
android:layout_centerHorizontal="true"
android:layout_below="@+id/buttonAboutUs" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About Us & Hours of Operation"
android:id="@+id/buttonAboutUs"
android:onClick="sendMessage"
android:layout_below="@+id/textView"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/textView" />
</RelativeLayout>
aboutus.xml 這是我想要的SER被送到後,按鈕被點擊
<?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="About Us"
android:id="@+id/AboutUs"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/editText"
android:text="We are dedicated to helping people get off tobacco! We carry everything from beginner setups, to advanced personalized vaporizers, as well as premium juices all made in house! "
android:layout_below="@+id/AboutUs"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:phoneNumber="false"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:text="[email protected]"
android:textStyle="bold"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="@+id/editText3"
android:layout_below="@+id/editText2"
android:text="1111 N RD Live, Ca "
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/editText4"
android:layout_below="@+id/editText3"
android:text="555-555-5555"
android:textStyle="bold"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText5"
android:layout_below="@+id/editText4"
android:text="facebook.com/eastbay"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText6"
android:layout_below="@+id/editText5"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:text="Instagram: @eastbay"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/editText7"
android:layout_below="@+id/editText6"
android:layout_alignParentBottom="true"
android:text="Monday - Saturday 10:00 am - 8:00 pm\n Sunday 10:00 am - 6:00 pm"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
</
你能詳細說一下嗎?我沒有真正遵循你的意思 – CosmoVitoriano