package net.stack3.listviewsample.choicesingle;

import java.util.List;

import net.stack3.listviewsample.R;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ChoiceSingleListItemAdapter extends ArrayAdapter<String> {
    public ChoiceSingleListItemAdapter(Context context, List<String> items) {
        super(context, 0, items);
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Context context = getContext();
        
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.choice_single_list_item,  parent, false); 
        }
        
        String item = getItem(position);
        
        TextView textView = (TextView)convertView.findViewById(R.id.textView);
        textView.setText(item);
        
        ListView listView = (ListView)parent;
        Resources resources = context.getResources();
        if (listView.getCheckedItemPosition() == position) {
            convertView.setBackgroundColor(resources.getColor(R.color.green));
        } else {
            convertView.setBackgroundColor(resources.getColor(R.color.white));
        }
        
        return convertView;
    }
}

@@ -513,24 +513,98 @@
 g%3E items) %7B%0A
+        // %E7%AC%AC2%E5%BC%95%E6%95%B0%E3%81%AE%E8%A1%8C%E3%81%AEresource ID%E3%81%AF%E3%81%93%E3%81%93%E3%81%A7%E3%81%AF0%E3%81%A7%E3%82%82%E8%89%AF%E3%81%84%E3%80%82getView%E3%81%A7resource%E3%82%92%E6%8C%87%E5%AE%9A%E3%81%97%E3%81%A6View%E3%82%92%E7%94%9F%E6%88%90%E3%81%99%E3%82%8B%E3%81%AE%E3%81%A7%E3%80%82%0A
         supe

Add comment.