我最近做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);
解决方案 »
- 有没有用mosquitto做推送的?有一个问题问一下
- .net程序后台如何直接读取Android手机MTP路径
- 关于viewpager的问题
- 求教!如何获取android的status bar的height???
- android4.0 开机启动后,显示的墙纸(称它为墙纸A)是存在什么地方呢?
- nexus s发短信出现乱码问题???
- 学android前需要掌握哪几门技术 求大牛解释
- 关于NDK对本地C++开发提供了多少支持的问题
- android 4.2启用AP功能后,怎么禁掉DHCP服务器功能(不是客户端)
- 使用Android CalendarListview 不显示问题
- IO流读取数据库文件出错,急求!
- 使用LayoutInflater 实例化layout布局xml文件
最近一个程序也用到了listview,listview的确不好操作,总是不按照预想的那样执行。