Android 尝试实现刷卡移动

Android 尝试实现刷卡移动,android,android-fragments,android-ui,Android,Android Fragments,Android Ui,公共课程活动扩展了Sherlock FragmentActivity{ ArrayList<CourseData> mCoursesList = new ArrayList<CourseData>(); public CoursesListAdapter coursesListAdapter; public ListView mList; public AlertDialog.Builder dlgAlert; public Dialog loginDialog; pu

公共课程活动扩展了Sherlock FragmentActivity{

ArrayList<CourseData> mCoursesList = new ArrayList<CourseData>();

public CoursesListAdapter coursesListAdapter;
public ListView mList;
public AlertDialog.Builder dlgAlert;
public Dialog loginDialog;
public Dialog loginDialogOverflow;

LinearLayout progressBar;
static SQLiteWebcourse dbHelper;
private GestureDetectorCompat mDetector;

public final static String EXTRA_MESSAGE = "com.technion.coolie.webcourse.MESSAGE";

public CoursesActivity() {
    dbHelper = new SQLiteWebcourse(this, "WebcoureDB", null, 1);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create list of courses
    mCoursesList = new ArrayList<CourseData>();
    setContentView(R.layout.web_activity_courses);
    mList = (ListView) findViewById(R.id.courses_list);
    dlgAlert = new AlertDialog.Builder(getApplicationContext());
    if (!CoolieAccount.WEBCOURSE.isAlreadyLoggedIn()) {

        loginDialog = CoolieAccount.WEBCOURSE.openSigninDialog(this);

        OnDismissListener dismissListener = new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {

                // Check if connection success
                if (CoolieAccount.WEBCOURSE.isAlreadyLoggedIn()) {
                    // Connection SUCCESS

                    progressBar = (LinearLayout) findViewById(R.id.progressBarLayout_courses);
                    progressBar.setVisibility(View.VISIBLE);

                    asyncParse<CourseData> a = new asyncParse<CourseData>() {

                        @Override
                        protected List<CourseData> doInBackground(
                                String... params) {
                            // TODO Auto-generated method stub
                            try {
                                courseList crL = new courseList(
                                        getApplicationContext());
                                crL.getCourses(CoolieAccount.WEBCOURSE
                                        .getUsername(),
                                        CoolieAccount.WEBCOURSE
                                                .getPassword());
                                mCoursesList = dbHelper
                                        .getAllCourses(CoolieAccount.WEBCOURSE
                                                .getUsername());
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            return super.doInBackground(params);
                        }

                        @Override
                        protected void onPostExecute(List<CourseData> result) {
                            // TODO Auto-generated method stub
                            CoursesListAdapter coursesListAdapter = new CoursesListAdapter(
                                    getApplicationContext(), mCoursesList);
                            mList.setAdapter(coursesListAdapter);
                            mList.setBackgroundColor(0xFFF0F0F0);
                            progressBar.setVisibility(View.INVISIBLE);
                            super.onPostExecute(result);
                        }

                    };
                    a.execute("");

                } else {
                    // Connection FAILED
                    Log.v("dbAss", "Second Time");

                }
            }
        };

        loginDialog.setOnDismissListener(dismissListener);

    } else {
        mCoursesList = dbHelper.getAllCourses(CoolieAccount.WEBCOURSE
                .getUsername());
        CoursesListAdapter coursesListAdapter = new CoursesListAdapter(
                getApplicationContext(), mCoursesList);
        mList.setAdapter(coursesListAdapter);
        mList.setBackgroundColor(0xFFF0F0F0);
    }
    Log.v("Gestures", "OnTouchEvent@!$#%@#%^&^$%");

    // OnItemClickListener itemClicked = new OnItemClickListener() {
    //
    // @Override
    // public void onItemClick(AdapterView<?> list, View view,
    // int position, long id) {
    // // TODO Auto-generated method stub
    // loadCourseInformationActivity(((CourseData) mList
    // .getItemAtPosition(position)).CourseDescription);
    // }
    // };
    // mList.setOnItemClickListener(itemClicked);
    mDetector = new GestureDetectorCompat(this, new MyGestureListener());
}



@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.v("Gestures", "OnTouchEvent@!$#%@#%^&^$%");

    this.mDetector.onTouchEvent(event);
    // Be sure to call the superclass implementation
    return super.onTouchEvent(event);
}

class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
    private static final String DEBUG_TAG = "Gestures";

    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2,
            float velocityX, float velocityY) {
        Log.v(DEBUG_TAG,
                "onFling: " + event1.toString() + event2.toString());
        Toast.makeText(getApplicationContext(), "SWIPED", Toast.LENGTH_LONG)
                .show();
        if (event2.getX() - event1.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
            Toast.makeText(getApplicationContext(), "SWIPED",
                    Toast.LENGTH_LONG).show();
        // if (showDeleteButton(e1))
        // return true;
        return super.onFling(event1, event2, velocityX, velocityY);
    }
}
ArrayList mCoursesList=new ArrayList();
公共课程列表适配器课程列表适配器;
公共列表视图mList;
public AlertDialog.Builder dlgAlert;
公共对话日志;
公共对话LoginDialogGoverFlow;
线性布局进度条;
静态SQLiteWebcourse-dbHelper;
私人手势检测器;
公共最终静态字符串EXTRA_MESSAGE=“com.technion.coulie.webcourse.MESSAGE”;
公共课程活动{
dbHelper=newsqlitewebcourse(这个“WebcoureDB”,null,1);
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//创建课程列表
mCoursesList=newarraylist();
setContentView(R.layout.web\u活动\u课程);
mList=(ListView)findViewById(R.id.courses\u列表);
dlgAlert=newalertdialog.Builder(getApplicationContext());
如果(!CoolieAccount.WEBCOURSE.isAlreadyLoggedIn()){
loginDialog=coulieaccount.WEBCOURSE.openSigninDialog(这个);
OnDismissListener dismissListener=新的OnDismissListener(){
@凌驾
公共void onDismiss(对话框接口对话框){
//检查连接是否成功
if(CoolieAccount.WEBCOURSE.isAlreadyLoggedIn()){
//连接成功
progressBar=(线性布局)findViewById(R.id.progressBarLayout_课程);
progressBar.setVisibility(View.VISIBLE);
asyncParse a=新的asyncParse(){
@凌驾
受保护列表背景(
字符串…参数){
//TODO自动生成的方法存根
试一试{
课程列表crL=新课程列表(
getApplicationContext());
crL.getCourses(CoolieAccount.WEBCOURSE
.getUsername(),
CoolieAccount.WEBCOURSE
.getPassword());
mCoursesList=dbHelper
.getAllCourses(CoolieAccount.WEBCOURSE)
.getUsername());
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回super.doInBackground(参数);
}
@凌驾
受保护的void onPostExecute(列表结果){
//TODO自动生成的方法存根
CoursesListAdapter CoursesListAdapter=新CoursesListAdapter(
getApplicationContext(),mcourseList);
mList.setAdapter(coursesListAdapter);
mslist.setBackgroundColor(0xFFF0);
progressBar.setVisibility(View.INVISIBLE);
super.onPostExecute(结果);
}
};
a、 执行(“”);
}否则{
//连接失败
Log.v(“dbAss”,“第二次”);
}
}
};
loginDialog.setOnDismissListener(dismissListener);
}否则{
mCoursesList=dbHelper.getAllCourses(CoolieAccount.WEBCOURSE
.getUsername());
CoursesListAdapter CoursesListAdapter=新CoursesListAdapter(
getApplicationContext(),mcourseList);
mList.setAdapter(coursesListAdapter);
mslist.setBackgroundColor(0xFFF0);
}
Log.v(“手势”,“OnTouchEvent@!$#%@#%^&^$%”;
//OnItemClickListener itemClicked=新建OnItemClickListener(){
//
//@覆盖
//public void onItemClick(适配器视图列表、视图、,
//内部位置,长id){
////TODO自动生成的方法存根
//加载课程信息活动(((课程数据)mList
//.getItemAtPosition(position)).CourseDescription);
// }
// };
//mList.setOnItemClickListener(itemClicked);
mDetector=new GestureDetectorCompat(这个,new MyGestureListener());
}
@凌驾
公共布尔onTouchEvent(运动事件){
Log.v(“手势”,“OnTouchEvent@!$#%@#%^&^$%”;
this.mDetector.onTouchEvent(事件);
//确保调用超类实现
返回super.onTouchEvent(事件);
}
类MyGestureListener扩展了GestureDetector.SimpleOnGestureListener{
私有静态最终字符串调试_TAG=“手势”;
@凌驾
公共布尔onFling(MotionEvent1、MotionEvent2、,
浮动速度x,浮动速度y){
Log.v(调试标签,
“onFling:”+event1.toString()+event2.toString());
Toast.makeText(getApplicationContext(),“滑动”,Toast.LENGTH\u LONG)
.show();
如果(event2.getX()-event1.getX()>滑动最小距离
&&Math.abs(velocityX)>滑动阈值(速度)
Toast.makeText(getApplicationContext(),“刷过”,
Toast.LENGTH_LONG).show();
//如果(显示删除按钮(e1))
//返回true;
返回super.onFling(event1、event2、velocityX、velocityY);
}
}
}

嘿,伙计们,我正在尝试实现刷卡检测。我上了安卓课程,完全按照上面写的做了:
由于某种原因,当我触摸屏幕时,它不会进入onTouchEvent。有什么问题吗?

您还没有将触控监听器设置为您的
列表视图

listView.setOnTouchListener(this);

在哪里初始化列表