我正在使用arrayadapter作为我的listview,我想在其中使用DownloadManager.但是数组适配器不知道这一行:
DownloadManager download =(DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Run Code Online (Sandbox Code Playgroud)
那么我怎么能使用这个我的适配器类,当用户触摸图像下载开始
我的适配器类:
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 = …Run Code Online (Sandbox Code Playgroud) 我正在使用AnimationDrawable进行下载进度吧我将动画放入getview,它运行正常.但是当我滚动列表时,动画已被停止.在AnimationDrawable中有任何方法来解决这个问题.喜欢Dialog中的setCancelable.
请帮帮我...谢谢
ImageView anim = (ImageView) rootview.findViewById(R.id.imageView2);
AnimationDrawable animation = (AnimationDrawable) anim.getDrawable();
animation.start();
Run Code Online (Sandbox Code Playgroud)
截图:

我正在使用CursorAdapter在listview中读取数据库.我在列表的每个项目中都有一个复选框,当用户选中复选框时,我的数据库中的收藏列会更改是,并且项目会添加到收藏夹中.
一切都很好,最喜欢的列已更改,但当我在列表中向上和向下滚动时,复选框将取消选中.如果您重新启动应用程序,则复选框已被选中
我该怎么办这个问题:
对不起,我的英语不好:
CursorAdapter类:
public class MyAdapter extends CursorAdapter {
Context b;
LayoutInflater inflater;
@SuppressWarnings("deprecation")
public MyAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
b= (Context) context;
}
@SuppressWarnings("unused")
@Override
public void bindView(View view, Context context, final Cursor cursor) {
// TODO Auto-generated method stub
TextView tv1 = (TextView)view.findViewById(R.id.txt_name);
TextView tv2 = (TextView)view.findViewById(R.id.txt_numer);
tv1.setText(cursor.getString(2));
tv2.setText(cursor.getString(3));
final int pos = cursor.getPosition();
final CheckBox repeatChkBx = (CheckBox)view.findViewById(R.id.favorite_check);
String me = cursor.getString(cursor.getColumnIndex("like"));
if (me.equals("yes")) {
repeatChkBx.setChecked(true);
} else {
repeatChkBx.setChecked(false); …Run Code Online (Sandbox Code Playgroud) 运行使用SqliteAssetHelper库的项目时出现此错误:
FATAL EXCEPTION: main
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 24
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思?
我读过这篇文章
但我无法解决我的问题.我在listview中使用CursorAdapter.
我在列表的每个项目中都有一个复选框.如果选中了复选框并向上和向下滚动.该复选框将被禁用.我无法解决它.请帮我.
@Override
public void bindView(View view, Context context, final Cursor cursor) {
TextView tv1 = (TextView)view.findViewById(R.id.txt_name);
TextView tv2 = (TextView)view.findViewById(R.id.txt_numer);
tv1.setText(cursor.getString(2));
tv2.setText(cursor.getString(3));
final int pos = cursor.getPosition();
final CheckBox repeatChkBx = (CheckBox)view.findViewById(R.id.favorite_check);
String likes = cursor.getString(cursor.getColumnIndex("like"));
if (likes.equals("yes")) {
repeatChkBx.setChecked(true);
} else {
repeatChkBx.setChecked(false);
}
repeatChkBx.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
MyDatabase mydatabase = new MyDatabase(b);
SQLiteDatabase mydb = mydatabase.getWritableDatabase();
cursor.moveToPosition(pos);
if (repeatChkBx.isChecked()) {
ContentValues cv = new ContentValues();
cv.put("like", "yes");
mydb.update("list", cv, "id …Run Code Online (Sandbox Code Playgroud)