0
我有一個資產文件夾中所有文件的列表視圖。 問題是,當我打開一個特定的文件,然後返回並打開Listview中的另一個文本文件時,它會打開前一個文件。前一個文件的清除緩衝讀取器
如何清除舊文件的緩衝區,以便我可以打開另一個文本文件。
public class Listapp extends Activity {
ListView mylistview;
ArrayList<String> array_filename;
ArrayList<String> array_textlocation;
ArrayAdapter<String> listAdapter;
Button btnStartQuiz;
TextView txtTitle, txtAuthor;
private QuizDriver quizDriver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listmain);
mylistview = (ListView)findViewById(R.id.listView1);
//here write folder name which one added assets folder
array_filename = new ArrayList<String>();
array_textlocation = new ArrayList<String>();
listAdapter = new ArrayAdapter<String>(Listapp.this,android.R.layout.simple_list_item_1, array_filename);
mylistview.setAdapter(listAdapter);
quizDriver = (QuizDriver) getApplication();
//For ListItem Click
mylistview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String s = array_filename.get(position);
String t = array_textlocation.get(position);
Toast.makeText(Listapp.this, "Selected File is " + s+t, 3000).show();
openFile("Myfiles/"+s, view.getContext());
Intent i = new Intent(view.getContext(), GeneralApp.class);
startActivityForResult(i,0);
}
});
String[] myfilesfolderlist = listAssetFiles("Myfiles");
for (int i = 0; i < myfilesfolderlist.length; i++) {
array_filename.add(myfilesfolderlist[i]);
array_textlocation.add("Myfiles/"+myfilesfolderlist[i]);
}
}
//Method for get files from Assets Folder and sub folder
private String [] listAssetFiles(String path)
{
String [] list;
try
{
list = Listapp.this.getAssets().list(path);
if (list.length > 0)
{
return list;
}
}catch (IOException e)
{
}
return null;
}
protected void openFile(String filename, Context context) {
InputStream is = null;
try {
is = context.getAssets().open(filename);
if (is != null) {
quizDriver.parseQuestionData(new BufferedReader(new InputStreamReader(is, "UTF-8")));
quizDriver.selectQuestions();
}
} catch (IOException e) {
Log.d("main activity", "IOException thrown");
}
}
}
仍然不能正常工作 – Vishal
它顯示以前打開的文件。 – Vishal
嘗試使用'myListView.invalidateViews()' – prat