adapter默认选中一个item代码

//效果如图

package util;

import java.util.List;
import java.util.Map;
import com.news.activity.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class AdapterUtil extends SimpleAdapter {
public AdapterUtil(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
private TextView cateitem;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//获得所有的view
View v=(TextView) super.getView(position, convertView, parent);
//设置默认选中第0个view
if (position == 0) {
cateitem=(TextView) v;
cateitem.setBackgroundResource(R.drawable.item);
cateitem.setTextColor(0XFFFFFFFF);// 此处不能引用xml文件里面的颜色
}
return v;
}

}

你可能感兴趣的:(Adapter)