I have four file in a subfolder in assets folder. I have written this code
@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();
}
}
});
All files are listing properly and want to show content of file in textview in listview but not reading files and showing FileNotFoundException. Please some one help..