好的,因为我没有你的整个代码库,所以我把一些简单的东西放在一起来复制你正在做的事情。仅供参考,我使用的是 ICS 4.1。我没有遇到您遇到的任何问题,所以这可能是 API 问题。也许你可以看看我的代码库,看看它和你自己的代码库有什么不同。其中可能存在解决方案。
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_rl"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top TextView" />
<Spinner
android:layout_below="@+id/textView4"
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/spinner1"
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Above EditText" />
<EditText
android:id="@+id/bleedCount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView5"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/abrMult"
android:ems="10"
android:inputType="number" >
</EditText>
<TextView
android:id="@+id/abrMult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView5"
android:layout_alignBaseline="@+id/abrSubmit"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/abrSubmit"
android:text="x12"
android:visibility="gone" />
<Button
android:id="@+id/abrSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView5"
android:text="Submit" />
</RelativeLayout>
代码:
public class ExampleActivity extends Activity implements OnItemSelectedListener {
private Button submitButton;
private TextView tv;
private Spinner spinner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
submitButton = (Button) findViewById(R.id.abrSubmit);
tv = (TextView) findViewById(R.id.abrMult);
spinner = (Spinner) findViewById(R.id.spinner1);
// create the data array for the spinner
String[] strings = { "This", "That", "The Other" };
// create the spinner adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, strings);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// set the adapter on the spinner
spinner.setAdapter(adapter);
// set the event listener for the spinner
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if (submitButton.getText().equals("Calculate")) {
submitButton.setText("Submit");
tv.setVisibility(View.GONE);
} else {
submitButton.setText("Calculate");
tv.setVisibility(View.VISIBLE);
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
希望能帮助到你...