【发布时间】:2018-06-18 03:48:34
【问题描述】:
我目前有一个listview,它在选择它后按字母顺序显示目录中的所有 .cue 文件,它使用外部程序来处理 .cue 文件。我想做的是在背景的imageview 中显示与提示文件匹配的缩略图。例如,如果我在同一目录中有一个名为“a.cue”和“a.png”的文件,当“a.cue”在listview 中突出显示时,
“a.png”同时在背景中显示为缩略图。这是我当前的代码:
public class openfileactivity7 extends Activity {
File path;
ListView list;
static ArrayList<String> bin_paths=new ArrayList<String>();
static ArrayList<String> bin_names=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (audioplay.isplayingAudio) {
} else {audioplay.playAudio(this, R.raw.boot);
}
list=(ListView)findViewById(R.id.listView1);
bin_paths.clear();
bin_names.clear();
path = new File("/mnt/usb_storage/USB_DISK0/udisk0/cue/pcecd");
searchFolderRecursive1(path);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, bin_names);
Collections.sort(bin_paths);
Collections.sort(bin_names);
adapter.sort(new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
return lhs.compareTo(rhs);
}
});
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String path = bin_paths.get(arg2);
File file = new File(path);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/cue");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
if (audioplay.isplayingAudio) {
audioplay.stopAudio();
}
startActivity(intent);
}
});
}
private static void searchFolderRecursive1(File folder)
{
if (folder != null)
{
if (folder.listFiles() != null)
{
for (File file : folder.listFiles())
{
if (file.isFile())
{
if(file.getName().contains(".cue"))
{
// Log.e("ooooooooooooo", "path__="+file.getName());
file.getPath();
bin_names.add(file.getName());
bin_paths.add(file.getPath());
// Log.e("bin_paths", ""+bin_names);
}
}
else
{
searchFolderRecursive1(file);
}
}
}
}
}
}
【问题讨论】:
-
这里的问题是什么?另外,您不是假装人们会为您阅读所有代码并修复它吗?只需告诉我们真正的问题在哪里,你走了多远,什么才是真正的阻碍。
-
我想问题是,我是程序员的初学者,虽然我了解如何显示和 imageview 并了解 listview 的工作原理,但我不确定它们是否可以并排实现。我不希望人们以任何方式解决它,但如果他们能指出一个资源或示例来解决类似的问题(正如我搜索但找不到答案),我们将不胜感激。
-
你的意思是这样的吗:stackoverflow.com/questions/9452989/… 第一个链接谷歌搜索这个问题......我想知道你之前甚至在谷歌上发帖吗
-
还是这个?第二个链接:androidcookbook.com/…
-
我做到了。几次。作为初学者,我深表歉意,感谢您向我展示一些示例。