我正在使用 SliderLayout 做滑动图像。默认情况下每 10 秒更改一次图像。如果用户想要更改时间间隔,请在设备本地内存中创建 interval.txt 文件并从该文件中获取间隔时间。现在我遇到的问题是,如果我在 interval.txt 中更改间隔时间,它会占用旧的时间间隔。你能指导我,如何解决这个问题。
protected void onCreate(Bundle savedInstanceState) {
writeFile();
ImageSlider();
}
public void writeFile(){
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(txtFile));
bw.write("10000");
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void ImageSlider() {
sliderLayout = (SliderLayout)findViewById(R.id.slider);
File file=new File("Images/");
File[] listFile = file.listFiles();
for (File f: listFile) {
.....
.....
}
for(String name : Hash_file_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(MainActivity.this);
......
......
}
try {
if ( new FileReader(txtFile) != null ) {
BufferedReader bufferedReader = new BufferedReader(new FileReader(txtFile));
String receiveString = "";
StringBuilder stringBuilder = new StringBuilder();
while ( (receiveString = bufferedReader.readLine()) != null ) {
stringBuilder.append(receiveString);
}
String ret = stringBuilder.toString();
sliderLayout.setDuration(Integer.parseInt(stringBuilder.toString()));
}
}
} catch (IOException e) {
}
sliderLayout.addOnPageChangeListener(this);
}