nima uchun onLongClickListener uchun bo'sh usul yaratib, menga bu xato android studiyasida beradi?

why when i create a void method for onLongClickListener gives me this error in android studio? Error =>

'onLongClick(View)' in 'Anonymous class derived from android.view.View.OnLongClickListener' clashes with 'onLongClick(View)' in 'android.view.View.OnLongClickListener'; attempting to use incompatible return type

mening kodim:

    myBTN.setOnLongClickListener(
            new Button.OnLongClickListener(){
                public void onLongClick(View v){
                    TextView lblm=(TextView) findViewById(R.id.txtMessage);
                    lblm.setText("Good Bye :| ");
                }
            }
    );

Lekin boolean usuldan foydalanganda xatolik yo'q

    myBTN.setOnLongClickListener(
            new Button.OnLongClickListener(){
                public boolean onLongClick(View v){
                    TextView lblm=(TextView) findViewById(R.id.txtMessage);
                    lblm.setText("Good Bye :| ");
                    return true;
                }
            }
    );
1

6 javoblar

android.view.View.OnLongClickListener interfeysi bilan tanishib chiqing. , < boolean funksiyasini qaytaradigan kodi> onClick (View) usulidan foydalaning. Qaytish qiymatiga ko'ra usullarni ortiqcha yuklay olmaysiz, shuning uchun bir xil argumentlar ro'yxatiga ega bo'lgan usulni belgilab, ammo boshqa qaytish turiga ega bo'lgan usulni tuzish xatosi hosil bo'ladi.

0
qo'shib qo'ydi

Bu usulni o'zgartirishni asosiy tushunchasi. Agar siz uni qaytarib olish turini o'zgartirib, usulni bekor qilishingiz mumkin. Agar bola sinfida ota-ona usuli bilan bir xil usul imzosi mavjud bo'lsa, uni bekor qilish usuli. Bu erda ota-ona Button.OnLongClickListener usuli mavjud bo'lgan interfeys, deb belgilaydi

interface Button.OnLongClickListener{

     public void onLongClick(View v);         

}

Shunday qilib, anonim sinfni qo'llash ham bir xil imzoga ega bo'lishi kerak.

0
qo'shib qo'ydi

Bu usulni o'zgartirishni asosiy tushunchasi. Agar siz uni qaytarib olish turini o'zgartirib, usulni bekor qilishingiz mumkin. Agar bola sinfida ota-ona usuli bilan bir xil usul imzosi mavjud bo'lsa, uni bekor qilish usuli. Bu erda ota-ona Button.OnLongClickListener usuli mavjud bo'lgan interfeys, deb belgilaydi

interface Button.OnLongClickListener{

     public void onLongClick(View v);         

}

Shunday qilib, anonim sinfni qo'llash ham bir xil imzoga ega bo'lishi kerak.

0
qo'shib qo'ydi

Ushbu usul allaqachon bu kodni yozgan jamoa tomonidan boolean deb e'lon qilingan, faqat ushbu dasturni bekor qilishi mumkin, ammo qaytish turiga emas, "usuli ustunlik"

0
qo'shib qo'ydi

Button can not have setOnLongClickListener you are supposed to implement the setOnLongClickListener as Button, based on View.class and View.class have an interface called onLongClickListener that have a method with the boolean type so you can always implement the setOnLongClickListener type as below:

button.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
               //your code here
                return false;
            }
    }); 

android studiyasida View.class ga qo'shimcha chiqishingiz mumkin, faqatgina OnLongClickListener ni bosgan bo'lsangiz, bu yordamni kuting.

0
qo'shib qo'ydi

Button can not have setOnLongClickListener you are supposed to implement the setOnLongClickListener as Button, based on View.class and View.class have an interface called onLongClickListener that have a method with the boolean type so you can always implement the setOnLongClickListener type as below:

button.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
               //your code here
                return false;
            }
    }); 

android studiyasida View.class ga qo'shimcha chiqishingiz mumkin, faqatgina OnLongClickListener ni bosgan bo'lsangiz, bu yordamni kuting.

0
qo'shib qo'ydi