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内。