这是我第一次尝试制作android应用程序,或者处理java,所以请耐心等待我的问题:(
我要做的是让屏幕上有几个按钮,当按下时,它会把用户带到另一组按钮的屏幕上。按下-2\f25 screen-2 \f6(屏幕)中的按钮后,用户将被带到一个新的屏幕,并根据按下的按钮和顺序显示一些文本。
每个屏幕上的其他按钮也是如此。
我已经有了一个满是按钮和ids的屏幕1。我甚至不确定下一部分从哪里开始。我可以为screen-1中的每个按钮创建onClick活动,但是screen-3如何记住screen-1和screen-2上按下的按钮?
activity_main.xml
<Button
android:id="@+id/button1"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:layout_weight="1"
android:text="@string/button1"
android:onClick="button1OnClick"/>
<Button
android:id="@+id/button2"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:layout_weight="1"
android:text="@string/button2"
android:onClick="button1OnClick2"/>MainActivity.java
public class Click extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main.xml);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// open up screen 2? do i use intent??
}
});
}}
activity_main2.xml
<Button
android:id="@+id/button1"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:layout_weight="1"
android:text="@string/button1"
android:onClick="button1OnClick"/>
<Button
android:id="@+id/button2"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:layout_weight="1"
android:text="@string/button2"
android:onClick="button1OnClick2"/>MainActivity2.java
public class Click extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main2.xml);
final Button button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// open up screen 3?
}
});
}}
screen-1和screen-2将共享同一组按钮。屏幕3将显示按下的顺序和按钮。
发布于 2013-06-19 04:43:25
发布于 2013-06-19 04:41:39
当您开始下一个活动时,您可以在意图中传递该信息。
例如,在你的protected void onCreate(Bundle savedInstanceState)中,你可以这样做:
Bundle extras = getIntent().getExtras();
if (extras != null) {
// test for the arg you passed in and extract value eg
String foostr = extras.getString(FOO_STRING);
int fooint = extras.getInt(FOO_INT);
}在启动活动的调用者中,
Intent intent = new Intent(this, Screen-2.class);
intent.putExtra(FOO_INT,myInt);
intent.putExtra(FOO_STRING,myString);
startActivity(intent);https://stackoverflow.com/questions/17178384
复制相似问题