English 中文(简体)
• 如何让Spinner选定项目价值加以说明?
原标题:How to get Spinner selected item value to string?

我有5个轴心。 总结一下。

甲型六氯环己烷

<Spinner
            android:id="@+id/text_interested"
            android:layout_span="2"
            android:layout_width="wrap_content"
            android:layout_height="60px"
            android:entries="@array/interestedarrays"
            android:prompt="@string/interestedprompt" />

in是Spinner

submitbtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        public void onItemSelected(
                                AdapterView<?> adapterView, View view,
                                int i, long l) {
                            interesting = interested.getItemAtPosition(i).toString();
                        }

                        public void onNothingSelected(
                                AdapterView<?> adapterView) {

                        }
                    });
    }
});

解释:

页: 1 该纽芬兰文在压力时将读到中枢的数据。 我对产出进行了核对。

System.out.println(interested.getItemAtPosition(i).toString());

它给我甚至没有结果。

• 如何收回价值并加以说明?

最佳回答

引证:

String text = mySpinner.getSelectedItem().toString();

如同这一点一样,你可以向不同的主轴取得价值。

问题回答
String Text = mySpinner.getSelectedItem().toString();

<>>>>

mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Object item = parent.getItemAtPosition(position);
    }
    public void onNothingSelected(AdapterView<?> parent) {
    }
});

可以通过使用、利用、从Spinner获得选定项目。

interested.getSelectedItem().toString();

2. 选定项目与科特林:

spinner.selectedItem.toString()

审判

 final Spinner cardStatusSpinner1 = (Spinner) findViewById(R.id.text_interested);
    String cardStatusString;
    cardStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent,
                View view, int pos, long id) {
            cardStatusString = parent.getItemAtPosition(pos).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

 final Button saveBtn = (Button) findViewById(R.id.save_button);
    saveBtn .setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            System.out.println("Selected cardStatusString : " + cardStatusString ); //this will print the result
        }
    });

如果您的Spinner是由Kumk的 cur子组成的,那么解决办法是:

Spinner mySpin = (Spinner) findViewById(R.id.myspin);
mySpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {  
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
           SQLiteCursor item = (SQLiteCursor) parent.getItemAtPosition(position);
           String value = String.valueOf(item.getString(0));
           Toast.makeText(getApplicationContext(), "The option is:" + value , Toast.LENGTH_SHORT).show(); 
 }

PS:item.getString(0) - &;0 是你希望获得的治疗器一栏索引。

除建议外,

String Text = mySpinner.getSelectedItem().toString();

你可以做到:

String Text = String.valueOf(mySpinner.getSelectedItem());

Since the latest language for Android Development is Kotlin. Here is, how we do it in Kotlin using Anonymous object.

spinnerName?.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
    override fun onNothingSelected(parent: AdapterView<*>?) {
       println("Nothing Selected")
    }

    override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
       val selectedString = yourList[position]
    }

}

我认为,当纽特被点击时,你想要 selected子的选定项目。

Try getS selectedItem(:

spinner.getSelectedItem()

当你从胎盘中选择任何价值时,你就获得了选定的价值。

interested.getSelectedItem().toString();

这样做的最佳途径是:

String selectedItem = spinner.getSelectedItem().toString();

可在以下网址查阅:Spinners

审判

sp1 = String.valueOf(spinner.getSelectedItem());

采用SpinnerAdapter, 供您的适应者使用,i 条码

    spinnerType = (AppCompatSpinner) findViewById(R.id.account_type);
    spinnerType.setPrompt("Select Type");

    spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            TypeItem clickedItem = (TypeItem) parent.getItemAtPosition(position);
            String TypeName = clickedItem.getTypeName();
            Toast.makeText(AddAccount.this, TypeName + " selected", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签