0

我在SQLite数据库中缓存了我的应用程序中获取的所有数据...每当用户没有互联网连接时,数据就会从数据库中加载一个SimpleCursorAdapter。 数据库还包含图像的URL。这些图像通过我正在使用的图像加载框架(Universal-Image-Loader)进行缓存,因此当我使用数据库中的URL运行框架时,它会获取缓存的图像。 我的问题是我如何在我的SimpleCursorAdapter中调用这个方法? 到目前为止,我只能从数据库中获取所有文本并将它们附加到TextView上...通过URL使用数据库中的图像

感谢您的帮助!

回答

0

所以,我终于能够完成这个工作我自己......

我不得不写延伸的CursorAdapter我不得不指派我所有的文本,我从有了新的方法......

有我数据库与TextView。所以,我也可以给我的图像装载机的链接(缓存)图像加载...

这是我的代码:

private static final class MyCursorAdapter extends CursorAdapter { 

    MyCursorAdapter(Context context, Cursor cursor, int flags) { 
     super(context, cursor, flags); 

     mInflater = LayoutInflater.from(context); 
    } 

    @Override 
    public View newView(Context context, Cursor cursor, ViewGroup parent) { 
     View v = mInflater.inflate(R.layout.row_twitter, parent, false); 
     return v; 
    } 

    @Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     TextView listtitle = (TextView) view.findViewById(R.id.listtitle); 
     TextView listusername = (TextView) view.findViewById(R.id.listusername); 
     TextView listdate = (TextView) view.findViewById(R.id.listdate); 

     listtitle.setText(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_TWEET))); 
     listusername.setText(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_USERNAME))); 
     listdate.setText(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_DATE))); 

     listtitle.setTextColor(Color.GRAY); 
     listdate.setTextColor(Color.GRAY); 

     ImageView iv = (ImageView) view.findViewById(R.id.image); 
     imageLoader.displayImage(cursor.getString(cursor.getColumnIndex(DataDBAdapter.KEY_TWITTER_IMAGEURL)), 
       iv, options); 
    } 

    LayoutInflater mInflater; 
} 

这实际上工作得很好:)

相关问题