package com.syf;
import android.view.View;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class TestActivity extends Activity {
GridView btnlist=null;
ListView list=null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
public void init()
{
list=(ListView)findViewById(R.id.list);
btnlist=(GridView)findViewById(R.id.btnlist);
btnlist.setAdapter(createGridAdapter());
btnlist.setOnItemClickListener(new ItemClickListener());
list.setAdapter(createListAdapter(new String[]{"s","2","r"}));
}
public ArrayAdapter<String> createListAdapter(String[] listdata)
{
List<String> data=new ArrayList<String>();
for(int i=0;i<listdata.length;i++)
{
data.add(listdata[i]);
}
return new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,data);
}
public SimpleAdapter createGridAdapter()
{
//构造数据源
ArrayList<HashMap<String, Object>> ImageItem = new ArrayList<HashMap<String, Object>>();
for(int i=0;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.ic_launcher);//图标资源
map.put("ItemText", "NO."+String.valueOf(i));//图标下方的文字
ImageItem.add(map);
}
//生成adapter
SimpleAdapter result = new SimpleAdapter(this, ImageItem, R.layout.item, new String[] {"ItemImage","ItemText"},new int[] {R.id.ItemImage,R.id.ItemText});
return result;
}
//监听器类
class ItemClickListener implements OnItemClickListener
{
public void onItemClick(AdapterView<?> arg0,//The AdapterView where the click happened
View arg1,//The view within the AdapterView that was clicked
int arg2,//The position of the view in the adapter
long arg3//The row id of the item that was clicked
) {
//在本例中arg2=arg3
HashMap<String, Object> item=(HashMap<String, Object>) arg0.getItemAtPosition(arg2);
setTitle((String)item.get("ItemText"));
String temp="你点击的是"+(String)item.get("ItemText");
list.setAdapter(createListAdapter(new String[]{temp}));
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
横向滑动菜单gridview+listview.rar (28个子文件)
test
.project 840B
bin
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
test.apk 17KB
resources.ap_ 12KB
classes
com
syf
R$string.class 394B
R$layout.class 421B
R$drawable.class 374B
R.class 454B
TestActivity$ItemClickListener.class 2KB
R$attr.class 307B
TestActivity.class 3KB
R$id.class 537B
classes.dex 5KB
proguard.cfg 1KB
AndroidManifest.xml 723B
src
com
syf
TestActivity.java 3KB
project.properties 360B
res
values
strings.xml 174B
layout
item.xml 909B
listitem.xml 491B
main.xml 1KB
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 3KB
.classpath 364B
gen
com
syf
R.java 1KB
assets
共 28 条
- 1
沙子而已
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页