我正在尝试创建下拉菜单,并通过从下拉列表中选择正确的波特率,数据应在python shell和消息框中显示串行端口数据,
下面提到的是我的代码:
============== RESTART: C:\Users\Misha\Desktop\test\dropTest.py ==============
Traceback (most recent call last):
File "C:\Users\Misha\Desktop\test\dropTest.py", line 31, in <module>
ard.baudrate = drop
NameError: name 'drop' is not defined
但是在运行这段代码时,我遇到了一些错误,
import android.content.Context
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
abstract class OnHorizontalSwipeListener(val context: Context) : View.OnTouchListener {
companion object {
const val SWIPE_MIN = 50
const val SWIPE_VELOCITY_MIN = 100
}
private val detector = GestureDetector(context, GestureListener())
override fun onTouch(view: View, event: MotionEvent) = detector.onTouchEvent(event)
abstract fun onRightSwipe()
abstract fun onLeftSwipe()
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onDown(e: MotionEvent) = true
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float)
: Boolean {
val deltaY = e2.y - e1.y
val deltaX = e2.x - e1.x
if (Math.abs(deltaX) < Math.abs(deltaY)) return false
if (Math.abs(deltaX) < SWIPE_MIN
&& Math.abs(velocityX) < SWIPE_VELOCITY_MIN) return false
if (deltaX > 0) onRightSwipe() else onLeftSwipe()
return true
}
}
}
我从各个方面进行了尝试,但无法解决。任何有关运行此代码的建议都会有很大帮助。