我在从 selector.xml 项目样式(背景)中设置我的列表视图时遇到问题
颜色没有切换它显示所有项目黑色,我想在黑色和白色之间切换项目颜色,现在的目标是从 listview 适配器切换项目颜色,但是当我从 listview 适配器切换项目颜色时,当我点击任何项目时,项目背景变蓝!
这是我的代码
public class Home_ForumsList_listview extends ArrayAdapter<Object>{
private int[] colors = new int[] { 0x30ffffff, 0x30808080 };
Context context;
private LayoutInflater mInflater;
@SuppressWarnings("rawtypes")
ArrayList ob;
int resource ;
/*================================================
* Setup ListView
*===============================================*/
@SuppressWarnings("unchecked")
public Home_ForumsList_listview (Context context, int resource, @SuppressWarnings("rawtypes") ArrayList objects) {
super(context, resource,objects);
this.context = context;
this.ob = objects;
this.resource = resource;
mInflater = LayoutInflater.from(context);
}
/*================================================
* Items Counter
*===============================================*/
public int getCount() {
return ob.size();
}
/*================================================
* Item Posistion JSON
*===============================================*/
public JSONObject getItem(JSONObject position) {
return position;
}
/*================================================
* Item Position
*===============================================*/
public long getItemId(int position) {
return position;
}
/*================================================
* Hold Views inside Chant Bit View
*===============================================*/
static class ViewHolder {
TextView forum_title;
TextView forum_desc;
TextView forum_catagories;
TextView forumcode;
Button popup_but_id;
RatingBar ratingsmall;
}
/*================================================
* Setup Each View raw by raw
*===============================================*/
public View getView(final int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
JSONObject r = (JSONObject) getItem(position);
if(convertView == null)
{
convertView = mInflater.inflate(R.layout.a_home_forumslist_bit, null);
holder = new ViewHolder();
convertView.setTag(holder);
holder.forum_title = (TextView) convertView.findViewById(R.id.flist_forum_title);
holder.forum_desc = (TextView) convertView.findViewById(R.id.flist_forum_desc);
holder.forum_catagories = (TextView) convertView.findViewById(R.id.flist_forum_catagories);
holder.forumcode = (TextView) convertView.findViewById(R.id.flist_forumcode);
holder.ratingsmall = (RatingBar) convertView.findViewById(R.id.ratingsmall);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
int colorPos = position % colors.length;
convertView.setBackgroundColor(colors[colorPos]);
try {
holder.forum_title.setText(r.getString("forum_title"));
if ( r.getString("forum_desc").equals(""))
{
holder.forum_desc.setVisibility(View.GONE);
}
float z = (float) r.getInt("rate");
holder.ratingsmall.setRating(z);
holder.forum_desc.setText(r.getString("forum_desc"));
holder.forumcode.setText( context.getString(R.string.forumcode) + " : ( "+ r.getLong("forumcode") + " ) ");
holder.forum_catagories.setText( " : " + r.getString("forum_catagories"));
} catch (JSONException e) {
e.printStackTrace();
}
return convertView;
}
}
我用谷歌搜索了如何设置 listview 的样式,所有显示相同颜色的示例都从 Adapter 切换,有没有办法从 selector.xml 设置 listview 项目的样式?
对不起我的英语不好^_^我希望你明白了