这是我的列表视图:
在我滚动此列表视图并单击例如“隐藏”后,将调用“收藏夹”操作(以及类似的错误 - 如果我按“压缩”,则会调用其他内容)。
这只发生在滚动之后。如果我不滚动 ListView,则永远不会。
这是我的适配器:
package com.landa.adapter;
import java.util.ArrayList;
import com.example.fileexplorermanager.R;
import com.landa.dialog.OperationsDialogFragment;
public class OperationsAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> data;
public OperationsAdapter(Context context, ArrayList<String> values) {
super(context, R.layout.operations_list_item, values);
this.context = context;
this.data = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//View rowView = inflater.inflate(R.layout.operations_list, parent, false);
View rowView = inflater.inflate(R.layout.operations_list_item, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.operation_name);
String temp = data.get(position);
String op_name = temp;
textView.setText(op_name);
ImageView imageView = (ImageView) rowView.findViewById(R.id.operation_image);
return rowView;
}
public int getCount() {
return data.size();
}
}
这是对话框(ListView 在对话框内):
public class OperationsDialogFragment extends DialogFragment {
// operation names
public static final String OP_CUT = "Cut";
public static final String OP_COPY = "Copy";
public static final String OP_RENAME = "Rename";
public static final String OP_DELETE = "Delete";
public static final String OP_SELECT_ALL = "Select all";
public static final String OP_SELECT_INVERSE = "Select inverse";
public static final String OP_CREATE_SHORTCUT = "Create shortcut";
public static final String OP_FAVORITE = "Favorite";
public static final String OP_HIDE = "Hide";
public static final String OP_COMPRESS = "Compress";
public static final String OP_SET_AS_HOME = "Set as home";
public static final String OP_PROPERTIES = "Properties";
ArrayList<String> operationsInfo = new ArrayList<String>();
private OperationsHandler opHandler;
private File f;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
opHandler = OperationsHandler.getInstance();
final String operation_type = getArguments().getString("operation_type");
final String file_absolute_path = getArguments().getString("file_absolute_path");
if(file_absolute_path != null)
this.f = new File(file_absolute_path);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
ArrayList<String> operationsList;
if (operation_type.equals("single_file")) {
setSingleFileDialogTitle(builder);
operationsList = getSingleFileOperationsList();
} else if (operation_type.equals("multiple_files")) {
setDefaultDialogTitle(builder);
operationsList = getMultipleFilesOperationsList();
} else {
setDefaultDialogTitle(builder);
operationsList = getDefaultOperationsList();
}
OperationsAdapter adap = new OperationsAdapter(getActivity(),
operationsList);
// upon operation click, execute operation
builder.setAdapter(adap, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String op_name = getOperationName(((AlertDialog) dialog)
.getListView().getChildAt(whichButton));
if (operation_type.equals("single_file")) {
executeSingleFileOperation(op_name);
} else {
executeMultipleFilesOperation(op_name);
}
}
});
return builder.create();
}
有什么问题?