我正在使用选择器属性处理列表视图,当用户选择索引位置时,该索引位置应突出显示,直到我选择列表视图的下一个索引位置,选择器属性适用于此,但是当我滚动列表视图时,选择器不起作用它在顶部移动。请在这件事上给予我帮助
<ListView
android:id="@+id/lvMenuItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@color/selected_color"
android:dividerHeight="3dp" >
</ListView>
lvMenu.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//view.setSelected(true);
Log.d("das","dasdas");
if(lastSelected != null) {
lastSelected.setBackgroundColor(Color.TRANSPARENT);//(dr/*id of your unselected drawable*/);
}
lastSelected = (ViewGroup)view;
lastSelected.setBackgroundResource(R.color.selected_color/*id of your selected drawable*/);
// selectedRow=position;
String photo =datasource.getImagePathFromSubMenuId(SubMnuIdlst.get(position));
Bitmap theImage= BitmapFactory.decodeFile(ofFilePath+"/"+photo);
Bitmap bitmapScaled = Bitmap.createScaledBitmap(theImage, 300,250, true);
drawable = new BitmapDrawable(bitmapScaled);
imgMainItem.setBackgroundDrawable(drawable);
Imagename=ServerPath+"images/"+photo;
String Desc=datasource.getSubMenuDescriptionFromSubMenuId(SubMenuid12);
tvDesc.setText(Desc);
selectionPos=position;
selectedimgpath=photo;
menuAdapter.notifyDataSetChanged();
Log.d("SelPos",""+selectionPos);
}
});