Spinner
package com.test.android;
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.Toast;
public class HelloAndroid extends Activity {
private static final String[] m_arr = {"第一组","第二组","第三组"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner _spin = (Spinner)findViewById(R.id.Spinner01);
ArrayAdapter<String> ada = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m_arr);
ada.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_spin.setAdapter(ada);
_spin.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
dispToast("选择的是"+m_arr[arg2]);
arg0.setVisibility(View.VISIBLE);
}
public void onNothingSelected(AdapterView<?> arg0){
//
}
});
}
public void dispToast(String str){
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}
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.Toast;
public class HelloAndroid extends Activity {
private static final String[] m_arr = {"第一组","第二组","第三组"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner _spin = (Spinner)findViewById(R.id.Spinner01);
ArrayAdapter<String> ada = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m_arr);
ada.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_spin.setAdapter(ada);
_spin.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
dispToast("选择的是"+m_arr[arg2]);
arg0.setVisibility(View.VISIBLE);
}
public void onNothingSelected(AdapterView<?> arg0){
//
}
});
}
public void dispToast(String str){
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}