gpt4 book ai didi

java - new View.OnClickListener(){} 类型中的 onClick(View, String) 方法永远不会在本地使用

转载 作者:行者123 更新时间:2023-12-01 12:17:53 24 4
gpt4 key购买 nike

下面的这些代码用于使用 PRINCE 算法加密短信并将短信发送给接收者。目前我面临一个问题,其中 public void onClick(View v,String args) 给出错误消息“The method onClick(View, String) from the type new View.OnClickListener() {} 从未在本地使用”。我还提到了The method onClick(View) from the type new Thread(){} is never used locally但给出的解决方案对我没有帮助。对于这个问题还有其他解决方案吗?

    btnSendSMS.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
String phoneNo = txtPhoneNo.getText().toString();
String message = txtMessage.getText().toString();
if (phoneNo.length()>0 && message.length()>0)
{
LongBuffer messageBuf = TooLong.messageToLongBuffer(message);
messageBuf.flip();
long[] messageData = new long[messageBuf.remaining()];
LongBuffer i = messageBuf.get(messageData);
String v1=prince.Encrypt(i, k0, kop, k1, t);
sendSMS(phoneNo, v1);
}
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
});
}

//---sends a SMS message to another device---

private void sendSMS(String phoneNumber, String v1)
{
/*
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, test.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
*/

String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);

PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);


//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));

//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, v1, sentPI, deliveredPI);
}
}

最佳答案

onClick() 方法的签名是 onClick(View),而不是 onClick(View,String)。后者声明了一个从未被调用的新方法,并且不会覆盖 OnClickListener 接口(interface)中的方法。

从方法中删除 String 参数,并删除另一个 stub onClick(View)

关于java - new View.OnClickListener(){} 类型中的 onClick(View, String) 方法永远不会在本地使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26880955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com