我尝试记住对话框中的复选框,但相比之下,记住== false,变量记住仍然没有更改其值。在循环中,在调用showDialogSameFile()之前迭代的次数与lelements_tmp一样多,所以我也不能在循环中使用变量。我该怎么做?提前谢谢。
private boolean remember = false;
// in the program
// add files to List lelements_tmp
while (i < lelements_tmp.size()) {
File fto = new File(lelements_tmp.get(i).getFile());
String to = null;
try {
to = fto.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
if (fto.exists()) {
showDialogSameFile(fto, to, i);
i++;
continue;
}
thread(i);
i++;
}
private void showDialogSameFile(File f, String to, final int i) {
TextView title = null;
if (f.isDirectory())
title = this.getTitle("The directory " + to + " already exists. Do you want to replace the contents?");
else if (f.isFile())
title = this.getTitle("The file " + to + " already exists. Do you want to replace it?");
String[] item = {"Apply to all"};
AlertDialog ad = new AlertDialog.Builder(context)
.setCustomTitle(title)
.setMultiChoiceItems(item, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
if (isChecked)
remember = true;
}
})
.setPositiveButton("Aceptar",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
thread(i);
}
})
.setNegativeButton("Cancelar",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.create();
if (remember == false)
ad.show();
}
答案 0 :(得分:0)
我必须稍微重构代码,但基本上是这项工作。有必要从非UI线程调用该方法。根据此回复https://stackoverflow.com/a/11369224/5089855
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char **argv) {
FILE *pPipe;
long lSize;
char * imgdata;
int imgcols = 640, imgrows = 480, elemSize = 3;
imgdata = ...;
stringstream sstm;
sstm << "/usr/local/bin/ffmpeg -y -f rawvideo -vcodec rawvideo -s " << imgcols << "x" << imgrows <<" -pix_fmt rgb24 -i - -c:v libx264 -shortest my_output.mp4";
if ( !(pPipe = popen(sstm.str().c_str(), "w")) ) {
cout << "popen error" << endl;
exit(1);
}
// open a pipe to FFmpeg
lSize = imgrows * imgcols * elemSize;
// write to pipe
fwrite(imgdata, 1, lSize, pPipe);
fflush(pPipe);
fclose(pPipe);
return 0;
}