【发布时间】:2015-01-09 11:19:22
【问题描述】:
我的适配器中有以下代码:
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView==null)
{
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.box_afisare, null);
}
final TextView titlu = (TextView) convertView.findViewById(R.id.titlu);
titlu.setText(Html.fromHtml(textt.get(position)));
titlu.setTextSize(TypedValue.COMPLEX_UNIT_SP,font);
final Integer pos = position;
titlu.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if (main_contextt.selectie.contains(id_post.get(pos)))
{
Toast.makeText(mContext," REMOVE ",Toast.LENGTH_LONG).show();
titlu.setBackgroundColor(Color.parseColor("#0077CC"));
}
else
{
main_contextt.selectie.add(id_post.get(pos));
titlu.setBackgroundColor(Color.parseColor("#404040"));
}
}
});
return convertView;
}
我设法为选定的一行或多行着色。但是当我滚动列表视图并且那些选定的行不再在手机的视图范围内时......背景颜色消失了。
只有当那条线/多条线不在视线范围内时它才会消失。我认为适配器正在重绘?
即使在我滚动列表视图后,如何保持行/行上的颜色设置?
谢谢
【问题讨论】:
标签: android listview android-listview adapter android-adapter