EDIT:あなたの質問
adapter = new ListAdapter(ListActivity.this , R.layout.custom_list , items);
listView.setAdapter(adapter);
public class ListAdapter extends ArrayAdapter <String>{
public ListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public ListAdapter(Context context, int resource, ArrayList<String> items) {
super(context, resource, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.itemlistrow, null);
}
LinearLayout ll = (LinearLayout)v.findViewById(R.id.ll);
TextView tv = (TextView)v.findViewById(R.id.tv);
if (position == 1) {
ll.setBackgroundColor(Color.BLACK);
tv.setTextColor(Color.WHITE);
}
if (position == 3) {
ll.setBackgroundColor(Color.BLACK);
tv.setTextColor(Color.WHITE);
}
if (position == 10) {
ll.setBackgroundColor(Color.BLACK);
tv.setTextColor(Color.WHITE);
}
tv.setText(items.get(position));
return v;
}
}
によると、ちょうどitemlistrow.xmlは、私はそれが今、あなたを助けますhopw
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
を下回っていることを確認します。
ビューが作成されたときのアダプタクラスでは、その位置変数を使用して、必要な項目や背景色に色を設定します。 – Sahil
どのアダプタクラスですか?申し訳ありませんが、私はアンドロイドを初めて使い、何を意味するのか分かりません。 – Fn20
ええ、あなたのアダプタクラスで...あなたはメソッドを使用してposition変数を使用し、それに応じてifまたはswitchを作成します。 – Sahil