我经历了这么多代码并试图找出我做错了什么,但我不及格并且在浪费时间。这将非常简单,但我无法弄清楚..
我正在开发一个 android 应用程序,需要在一个活动上放置 2 个微调器。第二个微调器将根据第一个微调器上选择的条目进行填充。听起来很简单吧?
所以这就是我想做的。如果用户选择Mobile,则choosePersonalPlan
应该显示来自的内容,当用户选择Large business 时chooseLargeBusplan
应该运行并且最终条目应该调用chooseSmallMedPlan
。我得到的只是一直ChooseSmallMedPlan
显示的项目。
这是我的代码。请让我知道我做错了什么!
Java 文件
package com.example.mobilebillforecaster;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
public class Du_postpaid extends Activity {
public Spinner catspinner,planspinner3,planspinner1,planspinner2;
protected void onCreate(Bundle mbfSplash) {
super.onCreate(mbfSplash);
setContentView(R.layout.postpaid);
chooseCategory();
choosePersonalPlan();
chooseLargeBusPlan();
chooseSmallMedPlan();
}
public void chooseCategory() {
catspinner = (Spinner) findViewById(R.id.catspinner);
ArrayAdapter<CharSequence> catAdapter = ArrayAdapter.createFromResource(this, R.array.ducategory, android.R.layout.simple_spinner_item);
catAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
catspinner.setAdapter(catAdapter);
}
private void choosePersonalPlan(){
planspinner1 = (Spinner) findViewById(R.id.planspinner);
List<String> planlist = new ArrayList<String>();
planlist.add("Elite Regular Plan");
planlist.add("Elite Super Plans");
planlist.add("Emirati Plan");
planlist.add("Pay As You Go");
planlist.add("Visitor Mobile Line");
ArrayAdapter<String> planAdapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, planlist);
planAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
planspinner1.setAdapter(planAdapter1);
}
private void chooseLargeBusPlan(){
planspinner2 = (Spinner) findViewById(R.id.planspinner);
List<String> planlist1 = new ArrayList<String>();
planlist1.add("Premier Plan");
planlist1.add("The Executive Plan");
planlist1.add("Business Circle Plan");
planlist1.add("Business Diamond Plan");
ArrayAdapter<String> planAdapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, planlist1);
planAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
planspinner2.setAdapter(planAdapter2);
}
private void chooseSmallMedPlan(){
planspinner2 = (Spinner) findViewById(R.id.planspinner);
List<String> planlist2 = new ArrayList<String>();
planlist2.add("Business Super Plan");
planlist2.add("Her Business Super Plan");
planlist2.add("Business Circle Plan");
planlist2.add("Pay As you Go® Plus");
ArrayAdapter<String> planAdapter3 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, planlist2);
planAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
planspinner2.setAdapter(planAdapter3);
}
public class planOnClickListener implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int pos,
long id) {
parent.getItemAtPosition(pos);
if (pos==0){
choosePersonalPlan();
}else if (pos==1){
chooseLargeBusPlan();
} else if (pos==2){
chooseSmallMedPlan();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
}
XML
<?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:gravity="left" >
<TextView
android:id="@+id/postp"
android:layout_width="130dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="@string/postp"
android:textSize="30dp"
/>
<Spinner
android:id="@+id/catspinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/postp"
android:layout_marginTop="25dp"
android:entries="@array/ducategory"
android:prompt="@string/category_prompt"
/>
<Spinner
android:id="@+id/planspinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/catspinner" />
</RelativeLayout>