私は非常に単純なことをしたいと思っています。アプリケーションに動的にテキストを追加するリストビューがあります。しかし、ある時点で、リストビュー内のテキストの色を変更したいと思います。そこで、カスタム リスト項目を定義する XML を作成し、ArrayAdapter をサブクラス化しました。しかし、カスタム ArrayAdapter で add() メソッドを呼び出すたびに、項目がリストビューに追加されますが、テキストはそこに配置されません。
ここに私のXMLがあります: `
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_content" android:textSize="8pt"
android:gravity="center" android:layout_margin="4dip"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#FF00FF00"/>
そして私の ArrayAdapter サブクラス:
private class customAdapter extends ArrayAdapter<String> {
public View v;
public customAdapter(Context context){
super(context, R.layout.gamelistitem);
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
this.v = convertView;
if(v==null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.gamelistitem, null);
}
if(timeLeft!=0) {
TextView tv = (TextView)v.findViewById(R.id.list_content);
//tv.setText(str[pos]);
tv.setTextColor(Color.GREEN);
}
else {
TextView tv = (TextView)v.findViewById(R.id.list_content);
//tv.setText(str[pos]);
tv.setTextColor(Color.RED);
}
return v;
}
}
私はひどく間違ったことをしていると確信していますが、私はまだ Android に少し慣れていません。
ありがとうございました!`