android-如何为if else语句使用微调器和数字选择器的选定值

android-如何为if else语句使用微调器和数字选择器的选定值,第1张

概述我想以某种方式同时使用数字选择器和微调器的值,即在选择微调器的值之后,数字选择器用户输入搜索,这将统计另一个具有列表视图的活动,我想根据选择的值显示列表的选择性项packagemyfyp.pkg.futureadvisor;importjava.util.ArrayList;importjava.util.List;importandroid.a

我想以某种方式同时使用数字选择器和微调器的值,即在选择微调器的值之后,数字选择器用户输入搜索,这将统计另一个具有列表视图的活动,我想根据选择的值显示列表的选择性项

package myfyp.pkg.futureadvisor;import java.util.ArrayList;import java.util.List;import androID.app.Activity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import androID.vIEw.VIEw;import androID.Widget.ArrayAdapter;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.NumberPicker;import androID.Widget.Spinner;import androID.Widget.TextVIEw;public class Enter_Info_Activity extends Activity {       TextVIEw t1,t2,t3;       EditText e1,e2;       button b1;       private Spinner spinner2;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.enterinfor);        t1=(TextVIEw) findVIEwByID(R.ID.textVIEw1);        t2=(TextVIEw) findVIEwByID(R.ID.programe);        e1=(EditText) findVIEwByID(R.ID.editText1);        t3=(TextVIEw) findVIEwByID(R.ID.percentage);        addItemsOnSpinner2();        NumberPicker np = (NumberPicker) findVIEwByID(R.ID.np);        np.setMinValue(0);        //Specify the maximum value/number of NumberPicker        np.setMaxValue(100);        //Gets whether the selector wheel wraps when reaching the min/max value.        np.setWrapSelectorWheel(true);        //Set a value change Listener for NumberPicker        b1 = (button) findVIEwByID(R.ID.search);        b1.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                // Todo auto-generated method stub                Intent intenet=new Intent(v.getContext(),List_item.class);                startActivityForResult(intenet,0);              }        });    }     public voID addItemsOnSpinner2() {            spinner2 = (Spinner) findVIEwByID(R.ID.spinner2);            List<String> List = new ArrayList<String>();            List.add("Bachelor of Architecture");            List.add("Bachelor of Business administration");            List.add("Bachelor of Commerce");            List.add("Bachelor of Computer information Systems");            List.add("Bachelor of ScIEnce in Construction Technology");            List.add("Bachelor of Criminal Justice");            List.add("Bachelor of Economics");            List.add("Bachelor of Education");            List.add("Bachelor of Engineering");            List.add("Bachelor of Fine Arts");            List.add("Bachelor of information Systems");            List.add("Bachelor of Social Work");            List.add("Bachelor of Technology");            List.add("Bachelor of Accountancy");            List.add("Bachelor of ScIEnce in Aerospace Engineering");            List.add("Bachelor of ScIEnce in Architecture");            List.add("Bachelor of ScIEnce in Architectural Engineering");            List.add("Bachelor of ScIEnce in Business administration");            List.add("Bachelor of ScIEnce in Business and Technology");            List.add("Bachelor of ScIEnce in Chemical Engineering");            List.add("Bachelor of ScIEnce in Chemistry");            List.add("Bachelor of ScIEnce in Civil Engineering");            List.add("Bachelor of ScIEnce in Computer Engineering");            List.add("Bachelor of ScIEnce in Computer ScIEnce");            List.add("Bachelor of ScIEnce in Criminal Justice");            List.add("Bachelor of ScIEnce in Electrical Engineering");            List.add("Bachelor of ScIEnce in Engineering Technology");            List.add("Bachelor of ScIEnce in English literature");            List.add("Bachelor of ScIEnce in Environmental ScIEnce");            List.add("Bachelor of ScIEnce in History");            List.add("Bachelor of ScIEnce in Human Resources Management");            List.add("Bachelor of ScIEnce in Industrial Engineering");            List.add("Bachelor of ScIEnce in information Technology");            List.add("Bachelor of ScIEnce in information Systems");            List.add("Bachelor of ScIEnce in information Systems");            List.add("Bachelor of ScIEnce in Integrated ScIEnce");            List.add("Bachelor of ScIEnce in Integrated ScIEnce");            List.add("Bachelor of ScIEnce in International Relations");            List.add("Bachelor of ScIEnce in Journalism");            List.add("Bachelor of ScIEnce in Manufacturing Engineering");            List.add("Bachelor of ScIEnce in Marketing");            List.add("Bachelor of ScIEnce in Mathematics");            List.add("Bachelor of ScIEnce in Mechanical Engineering");            List.add("Bachelor of ScIEnce in Mining Engineering");            List.add("Bachelor of ScIEnce in Software Engineering");            List.add("Bachelor of ScIEnce in Physics");            List.add("Bachelor of ScIEnce in Politics");            List.add("Bachelor of ScIEnce in Psychology");            List.add("Bachelor of ScIEnce in Real-Time Interactive Simulation");            List.add("Bachelor of ScIEnce in Religion");            List.add("Bachelor of ScIEnce in Risk Management and Insurance");            List.add("Bachelor of ScIEnce in ScIEnce Education");            List.add("Bachelor of ScIEnce in Systems Engineering");            List.add("Bachelor of ScIEnce in Veterinary Technology");            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,                androID.R.layout.simple_spinner_item, List);            dataAdapter.setDropDownVIEwResource(androID.R.layout.simple_spinner_dropdown_item);            spinner2.setAdapter(dataAdapter);          }    @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_activity1, menu);        return true;    }    @OverrIDe    public boolean onoptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroIDManifest.xml.        int ID = item.getItemID();        if (ID == R.ID.aboutusID) {            Intent aboutusintent = new Intent(this,Aboutus_Activity.class);             startActivity(aboutusintent);            return true;        }        else if (ID == R.ID.helpID) {            Intent helpIntent = new Intent(this,Help_Activity.class);             startActivity(helpIntent);            return true;        }        else if (ID == R.ID.homeID) {            Intent mainIntent = new Intent(this,MainActivity.class);             startActivity(mainIntent);            return true;}        else if (ID == R.ID.exitID) {            finish();            System.exit(0);        }        else if (ID == R.ID.exitID) {            return false;        }        return super.onoptionsItemSelected(item);    }}

解决方法:

您似乎正在寻找如何在活动之间传递数据.首先,您必须将NumberPicker设置为全局:

private Spinner mSpinner;private NumberPicker mNumberPicker;

考虑到这一点,您可以将数据发送到具有以下意图的新活动:

Intent intent = new Intent(v.getContent(), ListItem.class);intent.putExtra(ListItemActivity.EXTRA_MAJOR, mSpinner.getSelectedItem().toString());intent.putExtra(ListItemActivity.EXTRA_INT, mNumberPicker.getValue());startActivityForResult(intent, 0);

然后,您可以使用getIntent()在新的Activity中接收数据:

public class ListItemActivity extends AppCompatActivity {    public static final String EXTRA_MAJOR = "List_item:major";    public static final String EXTRA_INT = "List_item:int";    private int mInteger;    private String mMajor;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_item);        Intent intent = getIntent();        mMajor = intent.getStringExtra(EXTRA_MAJOR);        mInteger = intent.getIntExtra(EXTRA_INT);    }}
总结

以上是内存溢出为你收集整理的android-如何为if else语句使用微调器和数字选择器的选定值全部内容,希望文章能够帮你解决android-如何为if else语句使用微调器和数字选择器的选定值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1093668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存