android之点击事件ImageView切换
1、点击按钮按下抬起事件
poslistview.xml
<?xml version="1.0" encoding="utf-8"?>
android:layout_height="fill_parent"
android:orientation="vertical" >
android:layout_height="50dp"
android:background="#578cc2" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="3dp"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/mapmodel"
android:layout_toRightOf="@+id/return1"
android:src="@drawable/tit_03_parent" />
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@null"
android:scrollbarAlwaysDrawVerticalTrack="true" />
postlistview.java
public class PosListView extends ListActivity implements OnClickListener,
OnTouchListener {
....
private ImageView mapmode;
mapmode = (ImageView) findViewById(R.id.mapmodel);
mapmode.setOnClickListener(this);
mapmode.setOnTouchListener(this);
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()) {
case R.id.mapmodel:
if (event.getAction() == MotionEvent.ACTION_UP) {
Log.d("test", "cansal button ---> cancel");
mapmode.setBackgroundResource(R.drawable.ditu1);
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.d("test", "cansal button ---> down");
mapmode.setBackgroundResource(R.drawable.ditu2);
}
break;
}
return false;
}
2、点击listviewitem变色
在java中
this.getListView().setSelector(R.drawable.bg);
在drawable目录下建bg.xml
<?xml version="1.0" encoding="UTF-8"?>
3、点击listviwitem中的某个按钮变色
在listview.xml中
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/call"
/>
在drawabel目录下建立call.xml
<?xml version="1.0" encoding="utf-8"?>
更多相关文章
- android的四种点击事件的设置
- Android 点击按钮,文本文字改变
- android识别 单击和双击事件
- Android 监听Fragment界面的点击事件
- Android 下listview不能相应onItemClick事件
- android 添加桌面窗口小部件(托至桌面需要点击按钮才能生成的)
- Android 扫描SDCard上的音乐文件以及监听扫描事件
- Android事件传递机制【Touch事件】