android SimpleAdapter绑定onItemClickListener 点击每个图片按钮都跳转到不同的界面
publicclassmainformextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@Override...
public class mainform extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainform);
GridView gridview = (GridView) findViewById(R.id.gridview);
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
String[] SubName = new String[5];
SubName[0]="1";
SubName[1]="2";
SubName[2]="3";
SubName[3]="4";
SubName[4]="5";
for(int i=0;i<4;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.ic_launcher);
map.put("ItemText",SubName[i]);
lstImageItem.add(map);
}
SimpleAdapter saImageItems = new SimpleAdapter(this,
lstImageItem,
R.layout.night_item,
new String[] {"ItemImage","ItemText"},
new int[] {R.id.ItemImage,R.id.ItemText});
gridview.setAdapter(saImageItems);
gridview.setOnItemClickListener((OnItemClickListener) new ItemClickListener());
}
}
public class ItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
HashMap<String, Object> item=(HashMap<String, Object>)
arg0.getItemAtPosition(arg2);
//请问这里怎么写
}
} 展开
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainform);
GridView gridview = (GridView) findViewById(R.id.gridview);
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
String[] SubName = new String[5];
SubName[0]="1";
SubName[1]="2";
SubName[2]="3";
SubName[3]="4";
SubName[4]="5";
for(int i=0;i<4;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.ic_launcher);
map.put("ItemText",SubName[i]);
lstImageItem.add(map);
}
SimpleAdapter saImageItems = new SimpleAdapter(this,
lstImageItem,
R.layout.night_item,
new String[] {"ItemImage","ItemText"},
new int[] {R.id.ItemImage,R.id.ItemText});
gridview.setAdapter(saImageItems);
gridview.setOnItemClickListener((OnItemClickListener) new ItemClickListener());
}
}
public class ItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
HashMap<String, Object> item=(HashMap<String, Object>)
arg0.getItemAtPosition(arg2);
//请问这里怎么写
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询