删除 onSubmit() 方法



>我在互联网上找到了以下代码,我想知道如何删除onSubmit方法,即单击按钮且代码仍然有效。当我简单地删除该方法时,代码就会被销毁。

public class CellSignalStrength extends Activity{
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.info);
}
public void onSubmit(View v) {
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
int phoneType=tm.getPhoneType();
String ptype="";
switch(phoneType) {
case TelephonyManager.PHONE_TYPE_CDMA:
ptype="nPhone Type: CDMAn";
break;
case TelephonyManager.PHONE_TYPE_GSM:
ptype="nPhone Type: GSMn";
break;
case TelephonyManager.PHONE_TYPE_SIP:
ptype="nPhone Type: SIPn";
break;
case TelephonyManager.PHONE_TYPE_NONE:
ptype="nPhone Type: NONEn";
break;
}
tv.setText(ptype);
}
}

如果你想做onClick没有做的事情,只需将代码移动到里面

创建

喜欢这个

public class CellSignalStrength extends Activity{
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.info);
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
int phoneType=tm.getPhoneType();
String ptype="";
switch(phoneType) {
case TelephonyManager.PHONE_TYPE_CDMA:
ptype="nPhone Type: CDMAn";
break;
case TelephonyManager.PHONE_TYPE_GSM:
ptype="nPhone Type: GSMn";
break;
case TelephonyManager.PHONE_TYPE_SIP:
ptype="nPhone Type: SIPn";
break;
case TelephonyManager.PHONE_TYPE_NONE:
ptype="nPhone Type: NONEn";
break;
}
tv.setText(ptype);
}
}

最新更新