安卓大神告诉我怎么让ListView的点击事件(不是item的点击事件,屏蔽掉item的点击事件,就点击ListView本身)和上下滑动事件共存。
9条回答 默认 最新
关注 请参考:
package com.wps.android;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;public class Layouts extends Activity {
/** Called when the activity is first created. */
private ListView mylistview;
private ArrayList list = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mylistview = (ListView)findViewById(R.id.listview);
list.add("LinearLayout");
list.add("AbsoluteLayout");
list.add("TableLayout");
list.add("RelativeLayout");
list.add("FrameLayout");
ArrayAdapter myArrayAdapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1,list);
mylistview.setAdapter(myArrayAdapter);
/*mylistview.setOnTouchListener(new OnTouchListener(){@Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_DOWN) { mylistview.setBackgroundColor(Color.BLUE); } return false; } });*/ mylistview.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub if(list.get(arg2).equals("LinearLayout")) { Intent intent = new Intent("com.wps.android.LINEARLAYOUT"); startActivity(intent); } if(list.get(arg2).equals("AbsoluteLayout")) { Intent intent = new Intent("com.wps.android.ABSOLUTELAYOUT"); startActivity(intent); } if(list.get(arg2).equals("TableLayout")) { Intent intent = new Intent("com.wps.android.TABLELAYOUT"); startActivity(intent); } if(list.get(arg2).equals("RelativeLayout")) { Intent intent = new Intent("com.wps.android.RELATIVELAYOUT"); startActivity(intent); } if(list.get(arg2).equals("FrameLayout")) { Intent intent = new Intent("com.wps.android.FRAMELAYOUT"); startActivity(intent); } } }); }
}
解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog