我想在 EditText 框中输入一个 ip,然后通过按钮 ping 在 textView 中给出结果(是否可达)
public class MainActivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
EditText editText = (EditText) findViewById(R.id.editText1);
TextView textView = (TextView) findViewById(R.id.textView);
String input= editText.getText().toString();
InetAddress ip;
ip = InetAddress.getByName(input);
boolean reach= ip.isReachable(5000);
textView.setText("real ?"+reach);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
每当我在真机中按ping按钮时,它就会从应用程序中出来,为什么?