我以前项目也用过GridView,点击item有反应的,现在用不知道这么就没反应,代码很简单,一个activity,两个xml文件,如下:
public class WeiWoDuZunDetailActivity extends Activity { private String[] buttons = {"button1","button2","button3","button4","button5","button6",
"button7","button8","button9","back","button0","next"}; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weiwoduzundetail); GridView gridView = (GridView)findViewById(R.id.gridview_weiwoduzun); ArrayList<HashMap<String, String>> numList = new ArrayList<HashMap<String,String>>();
for(String button : buttons){
HashMap<String, String> map = new HashMap<String, String>();
map.put("key", button);
numList.add(map);
} SimpleAdapter adapter = new SimpleAdapter(this, numList, R.layout.item_weiwoduzundetail,
new String[]{"keyi"}, new int[]{R.id.btn_pageturning});
gridView.setAdapter(adapter); gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.v("test", "给点反应啊"); }
});
}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_ok"
android:text="确定" /> <GridView
android:id="@+id/gridview_weiwoduzun"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView></LinearLayout><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
> <Button
android:id="@+id/btn_pageturning"
android:layout_width="70dip"
android:layout_height="70dip"
android:layout_centerHorizontal="true"/></RelativeLayout>我在activity中加button,点击有响应,但gridView就是木有,求解答!gridviewandroid
public class WeiWoDuZunDetailActivity extends Activity { private String[] buttons = {"button1","button2","button3","button4","button5","button6",
"button7","button8","button9","back","button0","next"}; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weiwoduzundetail); GridView gridView = (GridView)findViewById(R.id.gridview_weiwoduzun); ArrayList<HashMap<String, String>> numList = new ArrayList<HashMap<String,String>>();
for(String button : buttons){
HashMap<String, String> map = new HashMap<String, String>();
map.put("key", button);
numList.add(map);
} SimpleAdapter adapter = new SimpleAdapter(this, numList, R.layout.item_weiwoduzundetail,
new String[]{"keyi"}, new int[]{R.id.btn_pageturning});
gridView.setAdapter(adapter); gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.v("test", "给点反应啊"); }
});
}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_ok"
android:text="确定" /> <GridView
android:id="@+id/gridview_weiwoduzun"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView></LinearLayout><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
> <Button
android:id="@+id/btn_pageturning"
android:layout_width="70dip"
android:layout_height="70dip"
android:layout_centerHorizontal="true"/></RelativeLayout>我在activity中加button,点击有响应,但gridView就是木有,求解答!gridviewandroid
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货