i'm using arrayadapter for my listview and i want to use DownloadManager in it. but the array adapter doesn't know this line :
DownloadManager download =(DownloadManager) getSystemService(DOWNLOAD_SERVICE);
so how can i use this im my adapter class that when the user touch the Image download starting
my adapter class :
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;
}
You need to pass the context also: EDIT:
DownloadManager download = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With