![](/img/trans.png)
[英]How to properly use the Android OnTouchListener and OnTouch function?
[英]How to use Onchanged and OnTouch for the same boutton in Android
我正在工作中开发 Android 应用程序,但遇到了问题。
我需要知道如何在条件下对同一个按钮使用Onchanged
和OnTouch
方法?
例如:如果我的按钮在左侧,那么您只能触摸它来执行某些操作,如果它在右侧,则您可以将其用作微调器。
我建议在这两种情况下都使用图像按钮。 根据您的要求,在左侧使用图像按钮作为普通按钮,在右侧使用微调器。 如果它在右侧,您可以使用要设置的变量“i”。 如果重置,请更改方法。
<ImageButton
android:id="@+id/imageButtonSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
/>
然后根据您需要的内容定义您的微调器。 像这样可能是......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="@+id/love"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton
android:id="@+id/hem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton
android:id="@+id/love"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
在主活动中
protected void onCreate(Bundle savedInstanceState) {
...
addListenerToSpinnerButton();
}
private void addListenerToSpinnerButton(){
spinnerButton = (ImageButton) findViewById(R.id.imageButtonSpinner);
spinnerButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
if(p != null)
showSpinner(MainActivity.this, p);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.