簡體   English   中英

如何在 Android 中為同一個按鈕使用 Onchanged 和 OnTouch

[英]How to use Onchanged and OnTouch for the same boutton in Android

我正在工作中開發 Android 應用程序,但遇到了問題。

我需要知道如何在條件下對同一個按鈕使用OnchangedOnTouch方法?

例如:如果我的按鈕在左側,那么您只能觸摸它來執行某些操作,如果它在右側,則您可以將其用作微調器。

我建議在這兩種情況下都使用圖像按鈕。 根據您的要求,在左側使用圖像按鈕作為普通按鈕,在右側使用微調器。 如果它在右側,您可以使用要設置的變量“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM