get text from text file and put in listView android code example
Example: list item in text file in listview asssets android
public class MainActivity extends Activity {
ListView list;
String path;
ArrayList<String> data = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView1);
path = getResources().getString(R.string.directory);
showlist();
}
private void showlist() {
String[] data1 = null;
AssetManager am = getResources().getAssets();
try {
data1 = am.list(path);
} catch (Exception e) {
}
for (String name : data1) {
String[] trimdata = null;
trimdata = name.split("\\.");
data.add(trimdata[0]);
}
list.setAdapter(new custlistview(data, MainActivity.this, path));
} }