我正在尝试从用户选择的选定图像中获取图像 URL,以便我可以将该字符串/URL 传递给我设置的另一个片段,以便可以通过图像视图完全查看图像。
我怎么能做到这一点?谢谢。
这是 SampleGridViewAdapter 类:
inal class SampleGridViewAdapter extends BaseAdapter {
private final Context context;
public final List<String> urls = new ArrayList<String>();
public SampleGridViewAdapter(Context context) {
this.context = context;
// Ensure we get a different ordering of images on each run.
Collections.addAll(urls, Data.URLS);
Collections.shuffle(urls);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SquaredImageView view = (SquaredImageView) convertView;
if (view == null) {
view = new SquaredImageView(context);
view.setScaleType(CENTER_CROP);
}
// Get the image URL for the current position.
String url = getItem(position);
// Trigger the download of the URL asynchronously into the image view.
Picasso.with(context) //
.load(url) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit() //
.into(view);
return view;
}
@Override
public int getCount() {
return urls.size();
}
@Override
public String getItem(int position) {
return urls.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
这是我的 SampleGridViewActivity:
public class SampleGridViewActivity extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.sample_gridview_activity,
container, false);
GridView Grid = (GridView) view.findViewById(R.id.grid_view);
Grid.setAdapter(new SampleGridViewAdapter(getActivity()));
Grid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long urls) {
// TODO Auto-generated method stub
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
Fragment openImage = new ImageViewPager();
transaction.replace(R.id.content_frame, openImage);
transaction.addToBackStack(null);
transaction.commit();
}
});
return view;
}
}
这是我想将字符串发送到的类:
public class ImageViewer extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.imageviewpager, container, false);
ImageView IMGView = (ImageView) view.findViewById(R.id.imageView1);
Picasso.with(getActivity()).load("Pass URL into HERE").into(IMGView);
return view;
}
}