My application is a manual that when the user clicks the item in the listView, the contained descriptions of each item, along with a photo, appear. Another thing like putting the .text data into a ListView. That is my doubt.
My application is a manual that when the user clicks the item in the listView, the contained descriptions of each item, along with a photo, appear. Another thing like putting the .text data into a ListView. That is my doubt.
Come on!
I'll show you how to load a .txt from the Assets folder:
create a file named dados.txt
inside the assets folder
It will have the following structure:
item 1;descrição um;image1.png
item 2;descrição dois;image2.png
To load this file use the following code:
/**
* Carrega um arquivo txt e transforma as linhas em Objeto.
*/
private void load(){
try {
final InputStream inputStream = getAssets().open("dados.txt");
final InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
final List<Item> itens = new ArrayList<MainActivity.Item>(0);
String line = "";
while ((line = buffreader.readLine()) != null){
String[] values = line.split(";");
final Item item = new Item(values[0], values[1], values[2]);
itens.add(item);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Representa o objeto que será exibido
*/
public static class Item {
public Item(final String title, final String description, final String image) {
this.title = title;
this.description = description;
this.image = image;
}
public String title;
public String description;
public String image;
}
I hope I have helped! Greetings!