我试图让每个图片将当前布局切换到分配给图像的布局。我坚持为图像分配ID(之后我将创建相应的布局(并为其分配ID,以便method
listen
点击layout
点击标识所点击图片的ID,以便切换到所需的package com.rogcg.gridviewexample;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter(new MyAdapter(this));
private class myClass implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
switch(parent.getId()) {
case R.id.listview1:
break;
case R.id.listview2:
break;
}
}
}
private class MyAdapter extends BaseAdapter {
private List<Item> items = new ArrayList<Item>();
private LayoutInflater inflater;
public MyAdapter(Context context) {
inflater = LayoutInflater.from(context);
items.add(new Item("Image 1", R.drawable.laptop_50));
items.add(new Item("Image 2", R.drawable.toast_50));
items.add(new Item("Image 3", R.drawable.rekawice_50));
items.add(new Item("Image 4", R.drawable.strych));
items.add(new Item("Image 5", R.drawable.ksiegozbior_50));
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int i) {
return items.get(i);
}
@Override
public long getItemId(int i) {
return items.get(i).drawableId;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v = view;
ImageView picture;
TextView name;
if (v == null) {
v = inflater.inflate(R.layout.gridview_item, viewGroup, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
v.setTag(R.id.text, v.findViewById(R.id.text));
}
picture = (ImageView) v.getTag(R.id.picture);
name = (TextView) v.getTag(R.id.text);
Item item = (Item) getItem(i);
picture.setImageResource(item.drawableId);
name.setText(item.name);
return v;
}
private class Item {
final String name;
final int drawableId;
Item(String name, int drawableId) {
this.name = name;
this.drawableId = drawableId;
}
}
}
}
使用布局的ID)。
(我的想法是制作一个应用程序,以照片的全屏网格开始切换到包含文本和图片的指定布局。(无填充,动画,设置,闪屏,滚动。))
{{1}}
activity_main.xml pastebin.com/0c9mZygz
gridview_item.xml pastebin.com/hQ0HVPDn
&#34;照片网格&#34;:http://i.stack.imgur.com/5yGfi.png