更改项目上行的背景色draglistview android
我正在使用 我的应用程序中的DragListView。我想在列表视图中的正确位置更改行的背景色。我怎样才能做到这一点?这是我到目前为止的代码片段:更改项目上行的背景色draglistview android,android,listview,drag-and-drop,listviewitem,Android,Listview,Drag And Drop,Listviewitem,我正在使用 我的应用程序中的DragListView。我想在列表视图中的正确位置更改行的背景色。我怎样才能做到这一点?这是我到目前为止的代码片段: public void checkOrderOfProcedures(){ mItemArray = new ArrayList<>(); mDragListView.setDragListListener(new DragListView.DragListListenerAdapter() { @Ove
public void checkOrderOfProcedures(){
mItemArray = new ArrayList<>();
mDragListView.setDragListListener(new DragListView.DragListListenerAdapter() {
@Override
public void onItemDragStarted(int position) {
}
@Override
public void onItemDragEnded(int fromPosition, final int toPosition) {
if (Long.valueOf(toPosition).equals((Long)(mItemArray.get(toPosition).first))) {
Toast.makeText(mDragListView.getContext(), "Correct position", Toast.LENGTH_SHORT).show();
class MyDragItem extends DragItem {
public MyDragItem(Context context, int layoutId) {
super(context, layoutId);
}
@Override
public void onBindDragView(View clickedView, View dragView) {
CharSequence text = ((TextView) clickedView.findViewById(R.id.text)).getText();
((TextView) dragView.findViewById(R.id.text)).setText(text);
dragView.setBackgroundColor(dragView.getResources().getColor(R.color.dialogRightBackground));
}
}
//change background color of the row (correct position) to green
//disable drag of a row if it is in correct position
mDragListView.setDragListCallback(new DragListView.DragListCallbackAdapter() {
@Override
public boolean canDragItemAtPosition(int dragPosition) {
return dragPosition != mItemArray.get(toPosition).first;
}
@Override
public boolean canDropItemAtPosition(int dropPosition) {
return dropPosition != mItemArray.get(toPosition).first;
}
});
} else {
Toast.makeText(mDragListView.getContext(), "Incorrect position", Toast.LENGTH_SHORT).show();
}
}
});
setupListRecyclerView();
listAdapter.notifyDataSetChanged();
}
private static class MyDragItem extends DragItem {
public MyDragItem(Context context, int layoutId) {
super(context, layoutId);
}
@Override
public void onBindDragView(View clickedView, View dragView) {
CharSequence text = ((TextView) clickedView.findViewById(R.id.text)).getText();
((TextView) dragView.findViewById(R.id.text)).setText(text);
dragView.setBackgroundColor(dragView.getResources().getColor(R.color.list_item_background));
}
}
public void checkOrderOfProcedures(){
mItemArray=新的ArrayList();
mDragListView.setDragListListener(新的DragListView.DragListListenerAdapter(){
@凌驾
已启动的公用事业单位(内部位置){
}
@凌驾
公共位置(起始位置的整数,最终整数位置){
if(Long.valueOf(toPosition).equals((Long)(mItemArray.get(toPosition.first))){
Toast.makeText(mDragListView.getContext(),“正确位置”,Toast.LENGTH\u SHORT.show();
类MyDragItem扩展了DragItem{
公共MyDragItem(上下文,int-layoutId){
super(上下文,layoutId);
}
@凌驾
BindDragView上的公共无效(查看单击查看,查看dragView){
CharSequence text=((TextView)clickedView.findViewById(R.id.text)).getText();
((TextView)dragView.findviewbyd(R.id.text)).setText(text);
setBackgroundColor(dragView.getResources().getColor(R.color.dialogRightBackground));
}
}
//将行(正确位置)的背景色更改为绿色
//如果行位于正确的位置,则禁用拖动该行
mDragListView.setDragListCallback(新的DragListView.DragListCallbackAdapter(){
@凌驾
公共布尔canDragItemAtPosition(int-dragPosition){
返回dragPosition!=mItemArray.get(toPosition).first;
}
@凌驾
公共布尔canDropItemAtPosition(int-dropPosition){
return dropPosition!=mItemArray.get(toPosition).first;
}
});
}否则{
Toast.makeText(mDragListView.getContext(),“位置不正确”,Toast.LENGTH\u SHORT.show();
}
}
});
setupListRecyclerView();
listAdapter.notifyDataSetChanged();
}
私有静态类MyDragItem扩展了DragItem{
公共MyDragItem(上下文,int-layoutId){
super(上下文,layoutId);
}
@凌驾
BindDragView上的公共无效(查看单击查看,查看dragView){
CharSequence text=((TextView)clickedView.findViewById(R.id.text)).getText();
((TextView)dragView.findviewbyd(R.id.text)).setText(text);
setBackgroundColor(dragView.getResources().getColor(R.color.list_item_background));
}
}
任何帮助都将不胜感激,谢谢