私は写真付きのGridViewを持っています。
requestPathでグリッドビューから全画面表示
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_me, container, false);
TextView t = (TextView) view.findViewById(R.id.textName);
name = MySharedPreferences.getInstance(getActivity()).getName();
t.setText(name);
gridView = (GridView) view.findViewById(R.id.gridPhoto);
img = new ImageAdapter(getActivity(), path);
gridView.setAdapter(img);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//code
}
});
requestPath();
return view;
}
()は、画像のURLとImageAdapterを設定します。 onItemClickで
が、私はこれがImageAdapter
public class ImageAdapter extends BaseAdapter {
private Context context;
private final LayoutInflater inflater;
private List<PathImage> path;
private String username = null;
public ImageAdapter(Context c, List<PathImage> path){
context = c;
this.path = path;
inflater = LayoutInflater.from(context);
}
public ImageAdapter(Context c, List<PathImage> path, String username){
context = c;
this.path = path;
inflater = LayoutInflater.from(context);
this.username = username;
}
@Override
public int getCount() {
return path.size();
}
@Override
public Object getItem(int position) {
return path.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ImageView imageView;
if (v == null) {
v = inflater.inflate(R.layout.gridview_item, parent, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
}
imageView = (ImageView) v.getTag(R.id.picture);
String url = "";
if(username == null) {
url = "http://example.com/image/" + MySharedPreferences.getInstance(context).getUsername() + "/";
}else{
url = "http://example.com/image/" + username + "/";
}
Glide.with(context).load(url + path.get(position).getPath()).into(imageView);
return v;
}
public void updatePath(List<PathImage> p){
path = p;
this.notifyDataSetChanged();
}
}
あるグリッド
で画像を取得したいと思い、私はGridViewの上でクリックしたときに別のフラグメントに画像を表示したいと思います。
イメージをあるフラグメントから別のフラグメントに移動するにはどうすればよいですか? ImageAdapterで
[answer](https://stackoverflow.com/a/12739968/5343320)をご確認ください。 – huk
イメージをクリックすると、イメージビューはどのように表示されますか? – Ibernato933
イメージビューを取得する必要はありません。 getvViewメソッドから画像ビューをクリックすると位置を取得できます。あなたのgetviewでonclicklistnerをimageviewに実装してください。これはあなたにポジションを与え、位置によって、あなたは以下のような値を得ることができます:url + path.get(position).getPath()そしてあなたのフラグメントに渡し、getviewで使ったのと同じロジックをグライドを使って – huk