我使用arrayadapter作为我的listview,我想在其中使用DownloadManager。 但阵列适配器不知道这一行:
DownloadManager download =(DownloadManager) getSystemService(DOWNLOAD_SERVICE);
那么我怎样才能使用这个我的适配器类,当用户触摸图像下载开始时
我的适配器类:
public class MyAdapter extends ArrayAdapter<String>{
private final Context context;
private final String[] values;
Context b;
public MyAdapter(Context context, String[] values) {
super(context, R.layout.item, values);
this.context = context;
this.values = values;
b= (Context) context;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootview = inflater.inflate(R.layout.item, parent, false);
TextView tv1 = (TextView)rootview.findViewById(R.id.txt_name);
TextView tv2 = (TextView)rootview.findViewById(R.id.txt_numer);
ImageView img = (ImageView) rootview.findViewById(R.id.imageView1);
MyDatabase MyDatabase = new MyDatabase(context);
SQLiteDatabase mydb = MyDatabase.getReadableDatabase();
Cursor cur = mydb.rawQuery("SELECT name,category,url FROM list WHERE id='"+values[position]+"'", null);
if (cur != null) {
cur.moveToFirst();}
tv1.setText(cur.getString(cur.getColumnIndex("name")));
tv2.setText(cur.getString(cur.getColumnIndex("category")));
return rootview;
}
答案 0 :(得分:4)
您还需要传递上下文: 编辑:
DownloadManager download = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);