package com.id2ip;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
public class id2ip extends Activity {
/** Called when the activity is first created. */
private TextView text;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获得文本框ID
text = (TextView)findViewById(R.id.editText1);
//获得按钮ID
button = (Button)findViewById(R.id.button1);
//重载按键监听方法
button.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
//获得输入框文本
CharSequence str = text.getText();
do
{
//判断输入是否有效
//如果输入位数不为8位,则无效
if (str.length() != 8)
{
text.setText("输入位数必须为8位");
break;
}
//输入的字符不为数字,则无效
int i = 0;
for (i = 0;i < 8;i++)
{
if ((str.charAt(i) < '0') || (str.charAt(i) > '9'))
{
break;
}
}
if (i < 8)
{
text.setText("输入字符必须为数字");
break;
}
String str_temp = str.toString();
//转换为数字
long num = Long.parseLong(str_temp);
//ip2id
short slave_num = (short)(num / 1000000);
num = num % 1000000;
short ip1 = (short)(num / 1000);
num = num % 1000;
short ip0 = (short)num;
long num_temp = ip0;
num_temp |= ip1 << 8;
num_temp |= slave_num << 16;
str_temp = Long.toString(num_temp);
str = str_temp;
text.setText(str);
}while (false);
}
});
}
}
CharSequence str; String str_temp = str.toString();
str = str_temp;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有