Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use DownloadManager in ArrayAdapter

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;
    }
like image 560
hamedjj Avatar asked May 17 '14 21:05

hamedjj


1 Answers

You need to pass the context also: EDIT:

DownloadManager download = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
like image 189
Ivan Skoric Avatar answered Oct 21 '22 12:10

Ivan Skoric