我有列表视图,在列表视图中我尝试在列表视图中显示图像后我想要更改图像大小并将其更新为列表视图..是否可以在运行时更新图像.... 以及如何获取当前显示的当前视图,我们可以修改它吗?? ??
这是上课....
public class GalleryAdapter extends BaseAdapter {
private Context mContext;
private int numcolumn;
private int NoOfListItem;
GridView grid;
int ListItemHeight;
private String[] header;
SharedPreferences groupbyPref;
private SharedPreferences GalleryPref;
ScreenshotLibrary myScreenshotLibrary = null;
// arrylist which contain path of images from sdcard..
ArrayList<String> itemList = new ArrayList<String>();
private TableLayout table_layout;
// layout parm of image
LinearLayout.LayoutParams parms;
public int fromback = 0;
ImageView img;
private LruCache<String, Bitmap> mMemoryCache;
private int size;
Cursor imagecursor;
int counter = 0;
// Constructor
@SuppressLint("NewApi")
public GalleryAdapter(Context gallery, int NumOfListItem, String[] str) {
}
@Override
public int getCount() {
return NoOfListItem;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return itemList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public void setnumcol(int i) {
grid.setNumColumns(i);
grid.requestLayout();
notifyDataSetChanged();
}
public int ListItemHeight(int length) {
SharedPreferences ImageSizePref = PreferenceManager
.getDefaultSharedPreferences(mContext);
if (length % numcolumn == 0) {
return ((length / numcolumn))
* ImageSizePref.getInt("ImageParm", 100) + 55;
} else {
return ((length / numcolumn) + 1)
* ImageSizePref.getInt("ImageParm", 100) + 55;
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
View customRow = inflater.inflate(R.layout.list_item, null);
// textview which display header of screenshot library
TextView txt = (TextView) customRow.findViewById(R.id.header);
txt.setText(header[position]);
// tablelayout which will be used to contain images inside that
table_layout = (TableLayout) customRow.findViewById(R.id.tableLayout);
int count = 0;
// loop for num of row in view
for (int i = 0; i < RowMaking(numcolumn); i++) {
//
TableRow row = new TableRow(mContext);
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
// inner loop used for number of images in each row of
// tablelayout....and num of
for (int j = 1; j <= numcolumn; j++) {
img = new ImageView(mContext);
img.setAdjustViewBounds(true);
if (count < itemList.size()) {
int resId = mContext.getResources().getIdentifier(
itemList.get(count++), "drawable",
mContext.getPackageName());
loadBitmap(resId, img);
// img.setLayoutParams(parms);
img.setLayoutParams(new LayoutParams(size, size));
Log.i("fromcache", "num" + counter);
img.getResources();
} else {
break;
}
row.addView(img);
}
table_layout.addView(row);
}
customRow.setLayoutParams(new ListView.LayoutParams(
ListView.LayoutParams.MATCH_PARENT, ListItemHeight(itemList
.size())));
return customRow;
}
答案 0 :(得分:0)
是的,您可以使用dynamicdata更新listview ..
只看本教程......
http://www.developerfusion.com/article/145373/android-listviews-with-dynamic-data/
我建议您使用piccaso图像...
使用易于使用的毕加索..
在适配器中..
@Override
public void getView(int position, View convertView, ViewGroup parent) {
ImageView view = (ImageView) convertView.findViewById(R.id.ranking_prod_pic);
Picasso.with(context).load(url).into(view); //url is image url
//you can resize image if you want
/* Picasso.with(context) .load(url) .resize(50, 50) .centerCrop() .into(view) */
}