This prog sends an assets directory listing to a TextView. How do I populate a Spinner with it instead? I want to select an mp3 from the directory to play. I cannot just change TextView to Spinner, since the Eclipse editor objects. ..... Thanks.
Note: I tried putting quotes around each filename in the string, and a comma between them,
so it would resemble the {"file1", "file2", "file3"} format, but no luck!
--------------------------------------------------------------------------
package com.example.read_assets_dir;
import java.io.IOException;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//mp3 files are in assets/myfiles dir
AssetManager am = getAssets();
TextView firstField =
(TextView)findViewById(R.id.textView1);
// this line would be omitted if spinner is used
firstField.setText("Directory: ASSETS/MYFILES \n");
try{
String[] files = am.list("myfiles");
for (int i = 0; i < files.length; i++) {
firstField.append("\n File:" + i + " name= " + files);
} //for .... use just files for spinner!!!
} //try
catch (IOException e){
e.printStackTrace();
} //catch
} //Bundle
} //MainActivity
Note: I tried putting quotes around each filename in the string, and a comma between them,
so it would resemble the {"file1", "file2", "file3"} format, but no luck!
--------------------------------------------------------------------------
package com.example.read_assets_dir;
import java.io.IOException;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//mp3 files are in assets/myfiles dir
AssetManager am = getAssets();
TextView firstField =
(TextView)findViewById(R.id.textView1);
// this line would be omitted if spinner is used
firstField.setText("Directory: ASSETS/MYFILES \n");
try{
String[] files = am.list("myfiles");
for (int i = 0; i < files.length; i++) {
firstField.append("\n File:" + i + " name= " + files);
} //for .... use just files for spinner!!!
} //try
catch (IOException e){
e.printStackTrace();
} //catch
} //Bundle
} //MainActivity
rientation="vertical"