-1

如何创建可以选择以下语言的选项菜单: 语言:英语、中文(简体)和马来西亚语

When English is selected the English values will be used When Chinese (Simplified) is selected the Chinese (Simplified)values will be used When Bahasa Malaysia is selected the Bahasa Malaysia Value will appear

4

1 回答 1

0

首先在您的布局 .xml 文件中添加以下标签

<Spinner android:id="@+id/my_spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="true"/>

现在你可以定义你的微调器必须做什么,通过实现onItemSelectedListener简单的例子如下:

package com.vimaltuts.android.spinner;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
public class SpinnerActivity extends Activity implements OnItemSelectedListener {
    /** Called when the activity is first created. */
    private TextView userSelection;
    private static final String[] items={"Android","Bluetooth","Chrome","Docs","Email",
        "Facebook","Google","Hungary","Iphone","Korea","Machintosh",
        "Nokia","Orkut","Picasa","Singapore","Turkey","Windows","Youtube"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        userSelection=(TextView)findViewById(R.id.user_selection);
        Spinner my_spin=(Spinner)findViewById(R.id.my_spinner);
        my_spin.setOnItemSelectedListener(this);
        ArrayAdapter aa=new ArrayAdapter(this, android.R.layout.simple_spinner_item,items);
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        my_spin.setAdapter(aa);
    }
    @Override
    public void onItemSelected(AdapterView arg0, View arg1, int pos,
            long arg3) {
        userSelection.setText(items[pos]);
    }
    @Override
    public void onNothingSelected(AdapterView arg0) {
        // TODO Auto-generated method stub
        userSelection.setText("");
    }
}

希望这可以帮助!!!

于 2013-08-16T05:00:55.157 回答