我正在编写一个有两个按钮的代码。点击第一个按钮,必须断开GSM网络,点击第二个按钮,必须连接GSM网络。我不想使用飞机模式。以下是我的代码:
package com.example.airplane;
public class MainActivity extends Activity {
// constants
ServiceState tmpServc = new ServiceState();
Button togState;
Button newState;
final int STATE_POWER_OFF = 3;
final int STATE_IN_SERVICE = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
togState = (Button)findViewById(R.id.togState);
newState = (Button)findViewById(R.id.button1);
// set click event for button
togState.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tmpServc.setState(STATE_POWER_OFF);
}
});
newState.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tmpServc.setState(STATE_IN_SERVICE);
}
});
}
请帮助我解决这个问题。或者除此之外还有更好的方法吗? 此致