我做了一个 FTP/FileBrowser Activity,让用户单击一个目录来导航到它,但是我想双击是必要的,因为该列表是用于批量删除、下载等的多选。我创建了一个 int var调用 remclickcount ,每次单击列表项时都会实现 ++,但是如果您单击目录 A 两次,它就可以正常工作。但是,如果您单击目录 A,然后单击目录 B,它会导航到目录 B。如何计算单个目录的点击次数?
remote.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
r_itla.setSelectedPosition(position);
String selectedFile = r_directoryEntries.get(position)
.getText();
boolean isDirectory = map.get(selectedFile).booleanValue();
if (isDirectory){
remclickcount++;
if(remclickcount==2) {
r_directoryEntries.clear();
r_itla.notifyDataSetChanged();
ftpPrintFilesList(selectedFile);
try {
FTPHelper.mFTPClient
.changeWorkingDirectory(selectedFile.toString());
remclickcount=0;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (!isDirectory) {
// Toast.makeText(FTPConnector.this, selectedFile,
// Toast.LENGTH_LONG).show();
currentRemoteFile = selectedFile;
}
}
});
工作代码:
remote.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
r_itla.setSelectedPosition(position);
String selectedFile = r_directoryEntries.get(position)
.getText();
boolean isDirectory = map.get(selectedFile).booleanValue();
if (isDirectory){
if(selectedFile.equals(lastClickSelectedFile)) {
r_directoryEntries.clear();
r_itla.notifyDataSetChanged();
ftpPrintFilesList(selectedFile);
try {
FTPHelper.mFTPClient
.changeWorkingDirectory(selectedFile.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(!selectedFile.equals(lastClickSelectedFile)){
lastClickSelectedFile = selectedFile;
}
} else if (!isDirectory) {
// Toast.makeText(FTPConnector.this, selectedFile,
// Toast.LENGTH_LONG).show();
currentRemoteFile = selectedFile;
}
}
});