我最近做android界面的时候遇到一个奇怪的现象,我在listview中添加了togglebutton,当只有listview时正常,但当在main.xml中的listview上方加入一个imageview的时候,点击listview中的第一个通过过了button,第9个,包括9的倍数的button都会被点,不知道是什么原因,哪位高手能指点一下,源码如下,依次为main.xml,item.xml,main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/cut"
/><ListView android:id="@+id/ListView01" android:layout_width="wrap_content"
android:layout_height="wrap_content"></ListView>
</LinearLayout><RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingBottom="4dip"
android:paddingLeft="12dip"
android:paddingRight="12dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBox android:id="@+id/CheckBox01"
android:layout_alignParentRight="true"
android:paddingTop="12dip"
android:layout_width="wrap_content"
android:focusable="false"
android:layout_height="wrap_content"></CheckBox><TextView android:text="TextView1" android:id="@+id/topTextView"
android:layout_width="fill_parent"
android:textSize="20dip"
android:layout_height="wrap_content"></TextView>
<TextView android:text="TextView2" android:id="@+id/bottomTextView"
android:layout_below="@+id/topTextView" android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView></RelativeLayout> super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myListView=(ListView)findViewById(R.id.ListView01);
ArrayList<HashMap<String, Object>> listitem=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<10;i++)
{
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("ItemTitle", "文章"+i);
map.put("ItemText", "Android 小項目"+i);
listitem.add(map);
}
SimpleAdapter listitemAdapter=new SimpleAdapter(this,//上下文
listitem, //數據
R.layout.item,//listItem的xml實現
new String[]{"ItemTitle","ItemText"}, //從map的批定Key
new int[]{R.id.topTextView,R.id.bottomTextView} //到要實現的控件上
);
myListView.setAdapter(listitemAdapter);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/cut"
/><ListView android:id="@+id/ListView01" android:layout_width="wrap_content"
android:layout_height="wrap_content"></ListView>
</LinearLayout><RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingBottom="4dip"
android:paddingLeft="12dip"
android:paddingRight="12dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBox android:id="@+id/CheckBox01"
android:layout_alignParentRight="true"
android:paddingTop="12dip"
android:layout_width="wrap_content"
android:focusable="false"
android:layout_height="wrap_content"></CheckBox><TextView android:text="TextView1" android:id="@+id/topTextView"
android:layout_width="fill_parent"
android:textSize="20dip"
android:layout_height="wrap_content"></TextView>
<TextView android:text="TextView2" android:id="@+id/bottomTextView"
android:layout_below="@+id/topTextView" android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView></RelativeLayout> super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myListView=(ListView)findViewById(R.id.ListView01);
ArrayList<HashMap<String, Object>> listitem=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<10;i++)
{
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("ItemTitle", "文章"+i);
map.put("ItemText", "Android 小項目"+i);
listitem.add(map);
}
SimpleAdapter listitemAdapter=new SimpleAdapter(this,//上下文
listitem, //數據
R.layout.item,//listItem的xml實現
new String[]{"ItemTitle","ItemText"}, //從map的批定Key
new int[]{R.id.topTextView,R.id.bottomTextView} //到要實現的控件上
);
myListView.setAdapter(listitemAdapter);
解决方案 »
- AndEngine连demo都跑不起来求助
- linux下如何给手机发AT命令?
- android SQLiteDatabase打开数据库文件后文件被删除--求真相
- 关于ndk opengl
- 什么是Android?在中国的发展及就业前景如何?
- 如何卸载删除方式
- 任务栏的通知,点开后,怎样才能点一下消失?
- 加入fragment之后 setonclickListener 报错
- Android LayoutTransition.CHANGE_DISAPPEARING问题
- android studio android monitor打不开问题
- IO流读取数据库文件出错,急求!
- 使用LayoutInflater 实例化layout布局xml文件
最近一个程序也用到了listview,listview的确不好操作,总是不按照预想的那样执行。