android onitemselected参数,如何在Android中使用onItemSelected?

package org.example.mbtiapplication;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.AdapterView.OnItemSelectedListener;

import android.widget.ArrayAdapter;

import android.widget.Spinner;

public class MBTITest extends Activity implements OnItemSelectedListener {

private Spinner firstSpinner;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_mbtitest);

Spinner firstSpinner = (Spinner) findViewById(R.id.spinner1);

// Create an ArrayAdapter using the string array and a default spinner layout

ArrayAdapter adapter = ArrayAdapter.createFromResource(this,

R.array.spinnerarraybool, android.R.layout.simple_spinner_item);

// Specify the layout to use when the list of choices appears

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// Apply the adapter to the spinner

firstSpinner.setAdapter(adapter);

}

@Override

public void onItemSelected(AdapterView> parent, View v, int position,

long id) {

// TODO Auto-generated method stub

}

@Override

public void onNothingSelected(AdapterView> arg0) {

// TODO Auto-generated method stub

}

}

XML布局:

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:layout_width="match_parent"

android:layout_height="wrap_content" >

android:layout_width="120dp"

android:layout_height="match_parent"

android:layout_marginLeft="5dp"

android:gravity="center_vertical"

android:text="I like to go out more than staying home." />

android:id="@+id/spinner1"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:layout_width="match_parent"

android:layout_height="wrap_content" >

android:layout_width="120dp"

android:layout_height="match_parent"

android:layout_marginLeft="5dp"

android:gravity="center_vertical"

android:textSize="10.5dp"

android:text="Sensing v Intuition" />

android:id="@+id/spinner2"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

我是一个新的Android程序员,使用Spinner时遇到麻烦,我已经尝试了多个教程,但仍然感到困惑。我想知道我的下一步是在这里,据我所知,我已经在Java中设置了我的微调器,在Java中我已经确定了微调器,为所述微调器创建了一个ArrayAdapter,并指定了一些选项。我不知道我是否已经填充了微调器,或者如何使用微调器对象。我想要使​​用微调对象来选择三个选项之一,然后将该值保留在微调框内的textview内。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值