これは私が再び見落としているかもしれない単純な問題であるに違いありません。これが私の問題ですstring.xmlに文字列配列があります
<string-array name="country_array">
<item>Alabama</item>
<item>Florida</item>
<item>Los Angeles</item>
<item>Virginia</item>
<item>California</item>
<item>Texas</item>
<item>Hawaii</item>
<item>Miami</item>
<item>New Jersey</item>
<item>Boston</item>
<item>Philadelphia</item>
<item>VaChina</item>
</string-array>
だから今、私は私の主な活動を呼びかけ、それを私のスピナーに置きました
selectedCountry = (EditText) findViewById(R.id.etCity);
//get the spinner from resource
Spinner spinner = (Spinner) findViewById(R.id.spinnerCountry);
//then defining ArrayAdapter using country_array
ArrayAdapter<CharSequence> adapter =ArrayAdapter.createFromResource(this, R.array.country_array,
android.R.layout.simple_spinner_item);
//set the appearance of widget items that show when open the widget
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//set the adapter to spinner
spinner.setAdapter(adapter);
//set the action listener
spinner.setOnItemSelectedListener(listener);
今私のスピナーの私のonclicklistenerでこれは私のコードです
View.OnClickListener selectCountry = new View.OnClickListener() {
public void onClick(View v) {
Spinner spinner = (Spinner) findViewById(R.id.spinnerCountry);
spinner.performClick();
}
};
private OnItemSelectedListener listener =new OnItemSelectedListener() {
//do what ever you want to do when item selected
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
//i get the item using selected item position and set it into selectedCountry
selectedCountry.setText(parent.getItemAtPosition(pos).toString());
}
public void onNothingSelected(AdapterView<?> parent) {
}
};
selectedCountryのテキストが配列の最初の項目であることがわかるまで、すべてが正常に機能します。エディットテキストにデフォルト値を追加できる方法はありますか?