我正在尝试增加微调器项目的大小。我已经使用了一个名为SPINNERVALUES
的数组,其中我已经声明了所有微调器项,我在我的XML文件中声明了它们,所以这可能是问题所在。
public class spinner extends AppCompatActivity {
Spinner spinner;
String[] SPINNERVALUES = {"BVP","SINGHAD","MIT"};
String SpinnerValue;
Button GOTO;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spinner);
spinner =(Spinner)findViewById(R.id.spinner1);
GOTO = (Button)findViewById(R.id.button1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(spinner.this,android.R.layout.simple_list_item_1,SPINNERVALUES);
spinner.setAdapter(adapter);
//Adding setOnItemSelectedListener method on spinner.
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
SpinnerValue = (String)spinner.getSelectedItem();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
GOTO.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(SpinnerValue) {
case "BVP":
intent = new Intent(spinner.this, CoverActivity.class);
startActivity(intent);
break;
case "SINGHAD":
intent = new Intent(spinner.this, CoverActivity.class);
startActivity(intent);
break;
case "MIT":
intent = new Intent(spinner.this, CoverActivity.class);
startActivity(intent);
break;
}
}
});
}
我的xml文件是
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:textStyle="bold"
android:background="#3F51B5"
android:textSize="20dp"
android:layout_below="@+id/spinner1"
android:layout_centerHorizontal="true"
android:layout_marginTop="81dp" />
答案 0 :(得分:1)
添加此代码:
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
在您的以下代码(设置适配器)之前:
spinner.setAdapter(adapter);
根据您的意愿修改您的下拉项目 - “simple_spinner_dropdown_item.xml”。 样品: -
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="4dp"
android:textSize="14sp"
android:typeface="serif"
android:singleLine="true"
android:layout_marginLeft="2dip"
android:layout_marginRight="5dip"
android:ellipsize="marquee"
android:textColor="#000000">
</TextView>
希望这会有所帮助。 :)