私はアンドロイドが初めてなので、助けが必要です..背景が白いxmlページがあります..その中にスピナーがあります..解析後にそのスピナーに値が入力されています..しかし問題は、クリックしたときですそのスピナーでは、テキストの色も白で、そのスピナーの背景も白です..したがって、テキストは表示されません..スピナーのすべてのアイテムを黒色にする必要があります..いくつかのスレッドがありますが、選択したアイテムだけが黒い色を示しているため、事前に ur hlp...thnx が必要です..
質問する
5710 次
2 に答える
6
スピナーの onItemSelected を実装している必要があります。このような:
public class YourActivity_Name extends Activity implements
AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner = (Spinner) findViewById(R.id.Spinner1);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
更新しました:
次に、次のようにスピナーにアイテムを設定する必要があります。
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
context, android.R.layout.simple_spinner_item,
array_spinner);
adapter.setDropDownViewResource(R.layout.simple_selectable_list_item);
spinner.setAdapter(adapter);
simple_selectable_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceListItem"
android:gravity="center_vertical"
android:background="?android:attr/listChoiceBackgroundIndicator"
android:paddingLeft="8dip"
android:textColor="#ff0000"
android:paddingRight="8dip"
/>
于 2013-06-18T05:38:41.833 に答える