使用两款Android纱厂一个因另一

使用两款Android纱厂一个因另一

本文介绍了使用两款Android纱厂一个因另一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经经历了这么多的code去,并试图找出什么我做错了,但我不及格,并在浪费时间。这将是pretty的简单,但我不出来..

我开发一个Android应用程序,并需要投入2纺纱厂的一个活动。第二离心器将填充基于关于第一离心器中选择的条目。听起来很简单吧?

因此​​,这里是我想做的事。如果用户选择了手机,从内容的 choosePersonalPlan 应显示,当用户选择大型企业 chooseLargeBusplan 应该运行和最终项应调用 chooseSmallMedPlan 。我得到的是从 ChooseSmallMedPlan 的项目显示所有的时间。

我的继承人code。请让我知道问心无愧我做错了!

的Java文件

 包com.example.mobilebillforecaster;

进口的java.util.ArrayList;
进口的java.util.List;

进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.ArrayAdapter;
进口android.widget.Spinner;
进口android.widget.AdapterView.OnItemSelectedListener;


 公共类Du_postpaid延伸活动{

    公共微调catspinner,planspinner3,planspinner1,planspinner2;


    保护无效的onCreate(包mbfSplash){
            super.onCreate(mbfSplash);
            的setContentView(R.layout.postpaid);

    chooseCategory();
    choosePersonalPlan();
    chooseLargeBusPlan();
    chooseSmallMedPlan();
    }

    公共无效chooseCategory(){

        catspinner =(微调)findViewById(R.id.catspinner);
        ArrayAdapter< CharSequence的> catAdapter = ArrayAdapter.createFromResource(这一点,R.array.ducategory,android.R.layout.simple_spinner_item);
        catAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        catspinner.setAdapter(catAdapter);

    }
    私人无效choosePersonalPlan(){
        planspinner1 =(微调)findViewById(R.id.planspinner);
        名单<字符串> planlist =新的ArrayList<字符串>();
        planlist.add(精英普通计划);
        planlist.add(精英超级计划);
        planlist.add(阿联酋计划);
        planlist.add(支付,因为你去);
        planlist.add(访问移动在线);
        ArrayAdapter<字符串> planAdapter1 =新的ArrayAdapter<字符串>(这一点,
            android.R.layout.simple_spinner_item,planlist);
        planAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        planspinner1.setAdapter(planAdapter1);

    }

    私人无效chooseLargeBusPlan(){

        planspinner2 =(微调)findViewById(R.id.planspinner);
        名单<字符串> planlist1 =新的ArrayList<字符串>();
        planlist1.add(premier计划);
        planlist1.add(以下简称执行计划);
        planlist1.add(商圈规划);
        planlist1.add(商务钻石计划);
        ArrayAdapter<字符串> planAdapter2 =新的ArrayAdapter<字符串>(这一点,
            android.R.layout.simple_spinner_item,planlist1);
        planAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        planspinner2.setAdapter(planAdapter2);


    }
    私人无效chooseSmallMedPlan(){

        planspinner2 =(微调)findViewById(R.id.planspinner);
        名单<字符串> planlist2 =新的ArrayList<字符串>();
        planlist2.add(商超计划);
        planlist2.add(她的生意超级计划);
        planlist2.add(商圈规划);
        planlist2.add(现收现付Go®加);
        ArrayAdapter<字符串> planAdapter3 =新的ArrayAdapter<字符串>(这一点,
            android.R.layout.simple_spinner_item,planlist2);
    planAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    planspinner2.setAdapter(planAdapter3);

    }


    公共类planOnClickListener实现OnItemSelectedListener {

            @覆盖
            公共无效onItemSelected(适配器视图<>母公司,视图V,INT POS机,
                    长ID){

                parent.getItemAtPosition(POS);

                如果(POS == 0){
                choosePersonalPlan();
                }否则如果(位置== 1){
                chooseLargeBusPlan();
                }否则,如果(POS == 2){
                chooseSmallMedPlan();
}
            }
            @覆盖
            公共无效onNothingSelected(适配器视图<>为arg0){
                // TODO自动生成方法存根

            }
            }


 }
 

XML

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:重力=左>

    <的TextView
        机器人:ID =@ + ID / postp
        机器人:layout_width =130dp
        机器人:layout_height =50dp
        机器人:layout_alignParentTop =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =15dp
        机器人:重力=中心
        机器人:文本=@字符串/ postp
        机器人:TEXTSIZE =30dp

        />


    <微调
        机器人:ID =@ + ID / catspinner
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_below =@ + ID / postp
        机器人:layout_marginTop =25dp
        机器人:项=@阵列/ ducategory
        机器人:提示=@字符串/ category_prompt
        />

     <微调
        机器人:ID =@ + ID / planspinner
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_below =@ + ID / catspinner/>


< / RelativeLayout的>
 

解决方案

添加

  catspinner.setOnItemSelectedListener(新planOnClickListener());
 

  chooseCategory();
 

下面是整个code -

 公共类TemoActivity延伸活动{

公共微调catspinner,planspinner3,planspinner1,planspinner2;


保护无效的onCreate(包mbfSplash){
        super.onCreate(mbfSplash);
        的setContentView(R.layout.main);

chooseCategory();
choosePersonalPlan();
chooseLargeBusPlan();
chooseSmallMedPlan();
}

公共无效chooseCategory(){

    catspinner =(微调)findViewById(R.id.catspinner);
    ArrayAdapter< CharSequence的> catAdapter = ArrayAdapter.createFromResource(这一点,R.array.ducategory,android.R.layout.simple_spinner_item);
    catAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    catspinner.setAdapter(catAdapter);
    catspinner.setOnItemSelectedListener(新planOnClickListener());
}
私人无效choosePersonalPlan(){
    planspinner1 =(微调)findViewById(R.id.planspinner);
    名单<字符串> planlist =新的ArrayList<字符串>();
    planlist.add(精英普通计划);
    planlist.add(精英超级计划);
    planlist.add(阿联酋计划);
    planlist.add(支付,因为你去);
    planlist.add(访问移动在线);
    ArrayAdapter<字符串> planAdapter1 =新的ArrayAdapter<字符串>(这一点,
        android.R.layout.simple_spinner_item,planlist);
    planAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    planspinner1.setAdapter(planAdapter1);

}

私人无效chooseLargeBusPlan(){

    planspinner2 =(微调)findViewById(R.id.planspinner);
    名单<字符串> planlist1 =新的ArrayList<字符串>();
    planlist1.add(premier计划);
    planlist1.add(以下简称执行计划);
    planlist1.add(商圈规划);
    planlist1.add(商务钻石计划);
    ArrayAdapter<字符串> planAdapter2 =新的ArrayAdapter<字符串>(这一点,
        android.R.layout.simple_spinner_item,planlist1);
    planAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    planspinner2.setAdapter(planAdapter2);


}
私人无效chooseSmallMedPlan(){

    planspinner2 =(微调)findViewById(R.id.planspinner);
    名单<字符串> planlist2 =新的ArrayList<字符串>();
    planlist2.add(商超计划);
    planlist2.add(她的生意超级计划);
    planlist2.add(商圈规划);
    planlist2.add(现收现付Go®加);
    ArrayAdapter<字符串> planAdapter3 =新的ArrayAdapter<字符串>(这一点,
        android.R.layout.simple_spinner_item,planlist2);
planAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
planspinner2.setAdapter(planAdapter3);

}


公共类planOnClickListener实现OnItemSelectedListener {

         @覆盖
        公共无效onItemSelected(适配器视图<>母公司,视图V,INT POS机,
                长ID){

            parent.getItemAtPosition(POS);

            如果(POS == 0){
            choosePersonalPlan();
            }否则如果(位置== 1){
            chooseLargeBusPlan();
            }否则,如果(POS == 2){
            chooseSmallMedPlan();
 }
        }
        @覆盖
        公共无效onNothingSelected(适配器视图<>为arg0){
            // TODO自动生成方法存根

        }
        }
}
 

I have gone through so much code and tried to figure out what I am doing wrong but i am flunked and am wasting time. It would be pretty simple but I cannot figure it out..

I am developing an android app and need to put 2 spinners on one activity. the second spinner will populate based on the entry selected on the first spinner. Sounds simple right?

So here is what I wanna do. If user selects Mobile, contents from the choosePersonalPlan should be displayed, when users selects Large business chooseLargeBusplan should run and the final entry should invoke chooseSmallMedPlan. All I get is the items from ChooseSmallMedPlan displaying all the time.

heres my code. please let me know wth I am doing wrong!

Java file

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>
解决方案

Add

catspinner.setOnItemSelectedListener(new planOnClickListener());

to

chooseCategory();

Here's the whole code-

public class TemoActivity extends Activity {

public Spinner catspinner,planspinner3,planspinner1,planspinner2;


protected void onCreate(Bundle mbfSplash) {
        super.onCreate(mbfSplash);
        setContentView(R.layout.main);

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);
    catspinner.setOnItemSelectedListener(new planOnClickListener());
}
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

        }
        }
}

这篇关于使用两款Android纱厂一个因另一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:32