【发布时间】:2012-03-20 06:16:56
【问题描述】:
我在SD card 的特定目录中有一些音频文件。我需要在 Android 的列表视图中显示他们的名字,如果我想播放或删除该特定文件,我可以通过该列表视图执行此操作吗?我该怎么做?
public class MyPerformanceArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MyPerformanceArrayAdapter(Context context, String[] values) {
super(context, R.layout.main, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.main, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
textView.setText(values[position]);
// Change the icon for Windows and iPhone
String s = values[position];
if (s.startsWith("Windows7") || s.startsWith("iPhone")
|| s.startsWith("Solaris")) {
//imageView.setImageResource(R.drawable.no);
} else {
//imageView.setImageResource(R.drawable.ok);
}
return rowView;
}
}
public class SimpleListActivity extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
MyPerformanceArrayAdapter adapter = new MyPerformanceArrayAdapter(this, values);
setListAdapter(adapter);
}
}
这段代码是一个简单的列表视图。我需要将它们的名称从特定目录中获取到适配器类。我该怎么做?
如果我对该特定文件进行任何更改,这些都应反映在列表视图中。
【问题讨论】:
标签: android listview audio android-layout