-1
我在資產文件夾的子文件夾中有四個文件。我寫了這個代碼獲取java.io.FileNotFoundException
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null){
convertView = LayoutInflater.from(context).inflate(R.layout.item_list, parent, false);
}
final TextView textView1 = (TextView) convertView.findViewById(R.id.textView1);
final TextView textView2 = (TextView) convertView.findViewById(R.id.textView2);
final Button show = (Button) convertView.findViewById(R.id.show1);
final Button hide = (Button) convertView.findViewById(R.id.hide1);
textView1.setText(data[position]);
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
show.setVisibility(View.INVISIBLE);
hide.setVisibility(View.VISIBLE);
try{
Resources resources = getResources();
AssetManager assetManager = resources.getAssets();
String fileList[] = assetManager.list("latest_trials");
if (fileList != null){
for (int i = 0; i < fileList.length; i++){
Log.v("Files", fileList[i]);
}
}
InputStream inputStream;
try{
inputStream = assetManager.open(fileList[position]);
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
String value = new String(buffer);
textView2.setMaxLines(Integer.MAX_VALUE);
textView2.setVisibility(View.VISIBLE);
textView2.setText(value);
}catch (IOException e){
e.printStackTrace();
}
}catch (IOException e){
e.printStackTrace();
}
}
});
所有文件都被正確地上市,並希望顯示在列表視圖TextView的文件的內容,但不讀文件並顯示FileNotFoundException異常。請有人幫忙..
價值? –
此代碼位於自定義列表適配器中的getview方法內。 – aquib23
請發表完整的code.Isue可能與位置變量的值 –