我想加載視頻的視頻縮略圖和文件名文本在目錄中。由於目錄中可能有很多vidoes,我需要使用AsyncTask。當我把代碼放在AsyncTask的getView()中時,我遇到了一堆錯誤。請告訴我我做錯了什麼。AsyncTask與圖像和文字
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();
}
什麼是那些錯誤和哪裏是aysnctask – Raghunandan
我的變量不工作,因爲他們在MyThumbnailAdapter類。然後,我將該類的一部分移至AsyncTask,但這也不起作用。 – user2250122
你會得到什麼樣的錯誤?你有一些logcat顯示?同時,您的getView()方法可能會遭受一些修改,您需要實現ViewHolder模式,其次您應該嘗試處理單獨線程中的位圖加載,您不希望有一個laggy列表視圖。 –