我正在尝试在目录中加载视频的视频缩略图和文件名文本。由于目录下可能有很多视频,所以我需要使用AsyncTask。当我将代码放在 AsyncTask 中的 getView() 中时,我得到了一堆错误。请告诉我我做错了什么。
public class MainActivity extends ListActivity {
String dirNameSlash = "/videos/";
String path = Environment.getExternalStorageDirectory() + dirNameSlash;
String root_sd = Environment.getExternalStorageDirectory().toString();
String theFile = root_sd + "/videos/";
File dir = new File(path);
{
assert (dir.exists());
assert (dir.isDirectory());
}
String[] videoFileList = dir.list();
public class MyThumbnaildapter extends ArrayAdapter<String> {
public MyThumbnaildapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
if (row == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.activity_main, parent, false);
}
TextView textfilePath = (TextView) row.findViewById(R.id.FilePath);
textfilePath.setText(videoFileList[position]);
ImageView imageThumbnail = (ImageView) row
.findViewById(R.id.Thumbnail);
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail(path
+ videoFileList[position], Thumbnails.MICRO_KIND);
imageThumbnail.setImageBitmap(bmThumbnail);
return row;
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MyThumbnaildapter(MainActivity.this,
R.layout.activity_main, videoFileList));
ListView lv = getListView();
}