[英]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.