12
我爲我的listview使用arrayadapter,並且我想在其中使用DownloadManager。 但陣列適配器不知道這行:如何在ArrayAdapter中使用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;
}
DownloadManager download =(DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE); – hamedjj