Преврати ресурс в прорисовку ....
setCompoundDrawablesWithIntrinsicBounds (getResources (). getDrawable (R.drawable.ic_folder_icon), null, null, null);
ОБНОВЛЕНИЕ С одним возможным правильным ответом:
public class FileListingActivity extends ListActivity {
private String mediapath = new String(Environment
.getExternalStorageDirectory().getAbsolutePath());;
private List<String> item = null;
private List<String> path = null;
private TextView mypath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.medialist);
mypath = (TextView) findViewById(R.id.mypath);
LoadDirectory(mediapath);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
if (new File(path.get(position)).isDirectory()){
LoadDirectory(path.get(position));
}
super.onListItemClick(l, v, position, id);
}
// class to limit the choices shown when browsing to SD card to media files
public class AudioFilter implements FileFilter {
// only want to see the following audio file types
private String[] extension = { ".aac", ".mp3", ".wav", ".ogg", ".midi",
".3gp", ".mp4", ".m4a", ".amr", ".flac" };
@Override
public boolean accept(File pathname) {
// if we are looking at a directory that's not hidden we want to see
// it so return TRUE
if (pathname.isDirectory() && !pathname.isHidden()) {
return true;
}
// loops through and determines the extension of all files in the
// directory
// returns TRUE to only show the audio files defined in the String[]
// extension array
for (String ext : extension) {
if (pathname.getName().toLowerCase().endsWith(ext)) {
return true;
}
}
return false;
}
}
private void LoadDirectory(String dirPath) {
mypath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles(new AudioFilter());
// If we aren't in the SD card root directory, add "Up" to go back to
// previous folder
if (!dirPath.equals(mediapath)) {
item.add("Up");
path.add(f.getParent());
// mediatext.setCompoundDrawablesWithIntrinsicBounds(
// R.drawable.ic_upicon, 0, 0, 0);
// mediatext.setCompoundDrawables(getResources().getDrawable(R.drawable.ic_upicon),
// null, null, null);
}
// Loops through the files and lists them
for (int i = 0; i < files.length; i++) {
File file = files[i];
path.add(file.getPath());
// Add "/" to indicate you are looking at a folder
if (file.isDirectory()) {
item.add(file.getName() + "/");
// mediatext.setCompoundDrawablesWithIntrinsicBounds(
// R.drawable.ic_foldericon, 0, 0, 0);
} else {
item.add(file.getName());
// mediatext.setCompoundDrawablesWithIntrinsicBounds(
// R.drawable.ic_audioicon, 0, 0, 0);
}
}
// Displays the directory list on the screen
setListAdapter(new ArrayAdapter<String>(this, R.layout.custom_row_view, item){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView;
if (convertView == null) { // if it's not recycled, initialize some
textView = new TextView(FileListingActivity.this);
} else {
textView = (TextView) convertView;
}
textView.setText(item.get(position));
if (item.get(position).equals("Up")){
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_upicon, 0, 0, 0);
}else if (new File(path.get(position)).isDirectory()){
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_foldericon, 0, 0, 0);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_audioicon, 0, 0, 0);
}
return textView;
}
});
}
}