目录 搜索
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
文字


Spinner

版本:Android 2.2 r1

 

public final class Spinner extends AbsSpinner

 

java.lang.Object

android.view.View

        android.view.ViewGroup

                android.widget.AdapterView<T extends android.widget.Adapter>

                        android.widget.AbsSpinner

                                android.widget.Spinner

 

类概述

        

下拉列表(Spinner)是一个每次只能选择所有项中一项的部件。它的项来自于与之相关联的适配器中。

 

XML属性

属性名称

描述

android:prompt

该提示在下拉列表对话框显示时显示。(译者注:对话框的标题:

 

公共方法

public int getBaseline()

返回这个控件文本基线的偏移量。如果这个控件不支持基线对齐,那么方法返回-1.

返回值

返回控件基线左边边界位置,不支持时返回-1

                   (译者注:这个类不知道干什么用,只找到下面的代码

     public class AndroidBamboo extends Activity 
{
    public void onCreate( Bundle savedInstanceState ) 
    {
     super.onCreate ( savedInstanceState );
        Spinner spinner = new Spinner ( this );
        spinner.setPrompt( "500" );
        String [ ] items = { "bam", "boo", "lab", "code", "programming", "framework", "android" };
        ArrayAdapter array_adapter = new ArrayAdapter <String> ( this, android.R.layout.simple_spinner_item, items );
        array_adapter.setDropDownViewResource ( android.R.layout.simple_spinner_dropdown_item );
        spinner.setAdapter ( array_adapter );
        int baseline = spinner.getBaseline ( );
        setContentView ( spinner );
    }

}

 

public CharSequence getPrompt()

         返回值    

当对话框弹出的时候显示的提示(译者注:获得弹出视图上的标题字)

 

public void onClick(DialogInterface dialog, int which)

当点击弹出框中的项时这个方法将被调用。

参数

dialog       点击弹出的对话框

which      点击按钮(如:Button)或者点击位置

 

public Boolean performClick()

如果它被定义就调用此视图的OnClickListener(译者注:例如可以在加载时默认弹出下拉列表)。

         返回值

True一个指定的OnClickListener被调用,为false时不被调用。

 

public void setOnItemClickListener(AdapterView.OnItemClickListener  I)

        Spinner不支持item的点击事件,调用此方法将引发异常。

参数

l        这个监听将被忽略

 

public void setPromptId(CharSequence prompt)

设置对话框弹出的时候显示的提示(译者注:设置弹出视图上的标题字)

参数

prompt     设置的提示

 

public void setPromptId(int promptId)

设置对话框弹出的时候显示的提示(译者注:设置弹出视图上的标题字)

参数

prompted 当对话框显示是显示这个资源id所代表的提示。

 

受保护的方法

protected void onDetachedFromWindow ()

当这个视图从屏幕上卸载时候被调用。在这一点上不再绘制视图。

 

protected void onLayout (boolean changed, int l, int t, int r, int b)

View要为所有子对象分配大小和位置时,调用此方法。派生类与子项们应该重载这个方法和调用布局每一个子项。

         参数

changed   这是这个视图的一个新的大小或位置

l        相对父空间的左位置

t        相对父空间的顶端位置

r        相对父空间的右端位置

b       相对父空间的底部位置

参见

Creates and positions all views

 

补充

         文章链接

                   Android学习指南——Spinner 下拉列表

                   android自定义Spinner下拉菜单(下拉列表框)样式

         示例代码

                   Java代码

public class SpinnerActivity extends Activity {

   

    String mes = "Wolf";

    private static final String[] m_arr = {"第一组","第二组","第三组"};

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

       Spinner s1 = (Spinner)findViewById(R.id.Spinner01);

       s1.setPrompt("请选择颜色" );

       //ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinnercolor,android.R.layout.simple_spinner_item);

       ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m_arr);

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

       s1.setAdapter(adapter); 

           s1.setSelection(1,true);

       //s1.setPromptId(CONTEXT_INCLUDE_CODE);

     

      

       int baseline = s1.getBaseline();

       s1.performClick();

       s1.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){

               //

           }

       });

         Toast.makeText(this, s1.getPrompt() ,Toast.LENGTH_LONG).show();

    }

    public void dispToast(String str){

        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();

    }  

}

XML文件

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="hello">Hello World, SpinnerActivity!</string>

    <string name="app_name">Spinner测试</string>

<string-array name="spinnercolor">

<item>红色</item>

<item>绿色</item>

<item>白色</item>

<item>橙色</item>

</string-array>

<string name="planet_prompt">Please Choose a Item</string>

</resources>


上一篇: 下一篇: