-2
我對Android應用程序非常陌生。爲每個Spinner選項打開不同的活動
我有一個微調設置,會有很多不同的選項。
你能幫我嗎?
我需要爲每個不同的微調器選項打開一個新的活動。
我該怎麼做?
activity_main.xml中
<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:gravity="top"
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=".MainActivity" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:entries="@array/model_numbers"
android:prompt="@string/model_spinner" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Please select model number below:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="[email protected]"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:text="Version 1.0"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
MainActivity.java
package com.example.capitaokipartslist;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
的strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Capita Oki Parts List</string>
<string name="action_settings">Settings</string>
<string name="model_number">Please select your model number:</string>
<string name="model_spinner">Please select your model number:</string>
<string-array name="model_numbers">
<item >C711</item>
<item >ES7411</item>
</string-array>
</resources>
張貼您的代碼 – Raghunandan
是否發佈您的代碼.. –
@raghunandan添加上面的代碼 –