package com.example.teleQ;import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.logging.Logger;
import com.example.Getinfo.CheckServer;
import com.example.teleQ.R.drawable;
import com.example.teleQ.R.layout;
import android.R.integer;
import android.R.menu;
import android.os.Bundle;
import android.os.Handler;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.webkit.WebView.FindListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
 
    private EditText eText;
    private TextView haomaduan;
    private TextView guishudi;
    private TextView yunyingshang;
    private TextView youzheng;
    private TextView quhao;
    private String[] html;
    private Handler handler;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        Button button= (Button) findViewById(R.id.button);
       eText=(EditText) findViewById(R.id.number);
       haomaduan=(TextView) findViewById(R.id.haomaduan);
       guishudi=(TextView) findViewById(R.id.guishudi);
       yunyingshang=(TextView) findViewById(R.id.yunyingshang);
       youzheng=(TextView) findViewById(R.id.youbian);
       quhao=(TextView) findViewById(R.id.quhao);
       button.setOnClickListener(new ButtonClickListener());
    } private final class ButtonClickListener implements View.OnClickListener{
public void onClick(View v) {

 //final String path = eText.getText().toString();
 String path="18739974467";   try {
     
     html = CheckServer.getHtml(path);
     haomaduan.setText("号码段:"+html[0]);  //号码段
 guishudi.setText("归属地:"+html[1]);             //归属地5
 yunyingshang.setText("运营商:"+html[2]);//运营商
 youzheng.setText("邮政编码:"+html[3]);      //邮政编码
 quhao.setText("区号:"+html[4]);   //区号 
  }
  catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "联网失败", 1).show();
}
}
    }
       public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu, menu);
          return true;
    }
     /* public boolean onPrepareOptionsMenu(Menu menu){
     Toast.makeText(getApplicationContext(), "菜单被显示之前的事件,可以在这里调整菜单", 1).show();
        
          return true;
          //必须返回True才能调用onCreateOptionsMenu(Menu menu)方法。
         }*/
   public boolean onOptionsItemSelected(MenuItem item) {
       switch (item.getItemId()) {
case R.id.help:

Intent intent=new Intent(MainActivity.this,helpActivity.class);
startActivity(intent);

 break;
             case R.id.quit://退出软件
MainActivity.this.finish();
     break;
             default:
              Toast.makeText(getApplicationContext(), "失败", 1).show();
              break;
}
  return false;
      }
   /*
    * (non-Javadoc)  这里写的是当按下返回按键时显示的情况
    * @see android.app.Activity#onBackPressed()
    */
   /* public void onBackPressed() {
            //在这里实现你的功能
          super.onBackPressed();
       
          Toast.makeText(getApplicationContext(), "要退出?", 1).show();
    }*/   public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
   {
     Dialog();
      }
  return false;
    }
    public void Dialog() {
          //  AlertDialog.Builder builder = new AlertDialog.Builder(this);
     AlertDialog.Builder builder =new AlertDialog.Builder(getApplicationContext());
            builder.setMessage(R.string.message);
            builder.setTitle("提示");
            builder.setPositiveButton(R.string.quxiao, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // FIRE ZE MISSILES!
                        dialog.dismiss();
                       }
                   });
           builder .setNegativeButton(R.string.quit, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // User cancelled the dialog                 
                        dialog.dismiss();
                        MainActivity.this.finish();
                       }
                   });
           builder.create().show();    }
 } 
有网友和我说安卓4.0以上的需要写入子线程,但是我更改以后还是不可以,那位懂得的朋友帮我改一下.我可以发源码过去.  
    
   
    

解决方案 »

  1.   


    Lz 应该先不要乱改,install到4.0板子上后,看FC日志信息来做相应的修改~
      

  2.   

    public void onClick(View v) {
    // TODO Auto-generated method stub
      final String path=eText.getText().toString();
      Runnable target=new Runnable() {

    public void run() {
    // TODO Auto-generated method stub
     if(path.length()==11)
        {
    try {
    String[] html = CheckServer.getHtml(path);
           haomaduan.setText("号码段:"+html[0]);  //号码段
       guishudi.setText("归属地:"+html[1]);             //归属地5
       yunyingshang.setText("运营商:"+html[2]);//运营商
       youzheng.setText("邮政编码:"+html[3]);      //邮政编码
       quhao.setText("区号:"+html[4]);   //区号
       } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    Toast.makeText(getApplicationContext(), "联网失败", 1).show();
           }
         }
    else {
    Toast.makeText(getApplicationContext(), "请输入11位手机号码", 1).show();
        }
    }
    };
    new Thread(targer).start();  

    }
     }
    改成这样,就会出现直接卡死的现象
      

  3.   

    new Thread去执行 html = CheckServer.getHtml(path);
    得到返回值后使用Handler去通知UI更新,
      haomaduan.setText("号码段:"+html[0]);  //号码段
     guishudi.setText("归属地:"+html[1]);             //归属地5
     yunyingshang.setText("运营商:"+html[2]);//运营商
     youzheng.setText("邮政编码:"+html[3]);      //邮政编码
     quhao.setText("区号:"+html[4]);   //区号