在 ListView 中,当我选择行时,它会设置背景颜色,并重置上一个选择的行。但是当 listview 向下滚动时,它显示选择了其他行相同的背景意味着一页一页向下滚动该行被选中。
请帮帮我
在这两个图像中,我只选择了第一行,但是当我滚动第 23 页时,已经选择了第 23 行。如何设置带有可滚动页面的选定行?
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setBackgroundResource(R.drawable.shape);
// on seleting single voter
// launching Edit Product Screen
lv.setOnItemClickListener(new OnItemClickListener() {
//mOnDoubleTapListener = listener;
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
boolean netFlag = new validationClass().haveNetworkConnection(context);
if(!netFlag) {
Toast.makeText(getApplicationContext(), "Data Connection is not available.", Toast.LENGTH_LONG).show();
return;
}
if (currentSelectedView != null && currentSelectedView != view) {
TextView textViewName = (TextView) currentSelectedView.findViewById(R.id.name);
TextView textViewPart = (TextView) currentSelectedView.findViewById(R.id.partno);
textViewName.setTextColor(getResources().getColor(android.R.color.darker_gray));
textViewPart.setTextColor(getResources().getColor(android.R.color.darker_gray));
} currentSelectedView =view
TextView textViewName = (TextView) view.findViewById(R.id.name);
TextView textViewPart = (TextView) view.findViewById(R.id.partno);
textViewName.setTextColor(getResources().getColor(R.color.text_color));
textViewPart.setTextColor(getResources().getColor(R.color.text_color));
}
}