解决方案 »

  1.   

    额,你贴下logcat日志呗,,,
      

  2.   

    好的,非常感谢你
    try {
    String uName=staticContent.uName;//获取用户名
    //设置标题
    TextView tvtitle=(TextView)findViewById(R.id.title);
    tvtitle.setText("工单处理");  
    //设置显示用户名
    TextView tvuname=(TextView)findViewById(R.id.txtUname);
    tvuname.setText(uName);

    group = (RadioGroup)findViewById(R.id.main_radio);

    tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
                    .setIndicator(TAB_HOME)
                    .setContent(new Intent(this,Gddaichuli.class)));  //.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)这句是选项卡切换刷新
            tabHost.addTab(tabHost.newTabSpec(TAB_MES)
                    .setIndicator(TAB_MES)
                    .setContent(new Intent(this,MainActivity.class)));
            tabHost.addTab(tabHost.newTabSpec(TAB_TOUCH)
         .setIndicator(TAB_TOUCH)
         .setContent(new Intent(this,Gdhuidan.class)));
            group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    public void onCheckedChanged(RadioGroup group, int checkedId) {
    switch (checkedId) {
    case R.id.radio_button0:
    tabHost.setCurrentTabByTag(TAB_HOME);
    break;
    case R.id.radio_button1:
    tabHost.setCurrentTabByTag(TAB_MES);
    break;
    case R.id.radio_button2:
    tabHost.setCurrentTabByTag(TAB_TOUCH);
    break;
    default:
    break;
    }
    }
    });
    } catch (Exception e) {
    // TODO: handle exception
    String error=e.toString();
     Dialog alertDialog = new AlertDialog.Builder(this). 
                    setTitle("1"). 
                    setMessage(error). 
                    setIcon(R.drawable.nt2). 
                    create(); 
            alertDialog.show(); 
    }
    }  Gddaichuli.java页面代码
    try {

    Uname=staticContent.LoginName;
    //启动数据加载动画
    showRoundProcessDialog(R.layout.loaddata);
    newthread=new Thread(daichuli);
    newthread.start();
    } catch (Exception e) {
    // TODO: handle exception
    String error=e.toString();
     Dialog alertDialog = new AlertDialog.Builder(this). 
                    setTitle("对话框的标题"). 
                    setMessage(error). 
                    setIcon(R.drawable.nt2). 
                    create(); 
            alertDialog.show(); 
    }
    }
    final Handler h=new Handler(){
    @Override
            public void handleMessage(Message msg){
                super.handleMessage(msg);
                if(msg.what==0)
                {
                 mDialog.dismiss();//关闭数据加载动画
                 Toast.makeText(getApplicationContext(),"没有数据",Toast.LENGTH_LONG).show(); 
                }
                if(msg.what==1)
                {
                 ArrayList result=new ArrayList();
                 result=(ArrayList) msg.obj;
                 //绑定Layout里面的ListView  
                    final ListView list = (ListView) findViewById(R.id.lvdaichuli);
                    //生成动态数组,加入数据 
                    List<HashMap<String,Object>> listItem=new ArrayList<HashMap<String,Object>>();
                    int temp=0;
                    int No=1;
                    for(int i=0;i<(result.size()/3);i++)
                    {
                     HashMap<String,Object> map=new HashMap<String,Object>();
                     map.put("NO",No);
                     map.put("ADSL",result.get(temp));
                     map.put("comName",result.get(temp+2));
                     listItem.add(map);
                     temp+=3;
                     No++;
                    }
                    //生成适配器的Item和动态数组对应的元素  
                    SimpleAdapter listItemAdapter = new SimpleAdapter(Gddaichuli.this,listItem,R.layout.lvdaichuli,new String[] {"NO","ADSL","comName"},new int[] {R.id.txtNO,R.id.textView2,R.id.textView1}); 
                     //添加并且显示  
                    list.setAdapter(listItemAdapter);  
                    mDialog.dismiss();//关闭数据加载动画
                }
    }
    };

    Runnable daichuli=new Runnable() {
    public void run() {
    getUrl u=new getUrl();
    ArrayList result=new ArrayList();
    result=u.daichuli(Uname);
    Message m=new Message();
    if(!(result.equals(null)))
    {
    m.what=1;
    m.obj=result;
    }
    else {
    m.what=0;
    }
    h.sendMessage(m);
    }
    }; public void showRoundProcessDialog(int layout)
        {
            OnKeyListener keyListener = new OnKeyListener()
            { @Override
    public boolean onKey(DialogInterface dialog, int keyCode,
    KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_SEARCH)
                    {
                        return true;
                    }
                    return false;
    }
            };        mDialog = new AlertDialog.Builder(this).create();
            mDialog.setCanceledOnTouchOutside(false);
            mDialog.setOnKeyListener(keyListener);
            mDialog.show();
            // 注意此处要放在show之后 否则会报异常
            mDialog.setContentView(layout);
        }
    }
      

  3.   

    第一段代码就可以了,我测试了,首先注意两个地方,tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
                    .setIndicator(TAB_HOME)
                    .setContent(new Intent(this,Gddaichuli.class)));这里new Intent后面的this有点泛指,可能造成指针不对,我改成了activity名.this,然后tabHost.setCurrentTabByTag(TAB_HOME);改成了tabHost.setCurrentTag()里面的参数是int,0,1,2,自己选择第几个画面,运行没报错,,,
      

  4.   

    我试了一下还是不行,改成
    tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
                    .setIndicator(TAB_HOME)
                    .setContent(new Intent(Gdhuidan.this,Gddaichuli.class))); 这样了
    还有这句tabHost.setCurrentTag(0);会报错:The method setCurrentTag(int) is undefined for the type TabHost
      

  5.   

    你的activity没有extends TabActivity吗?怎么会说这个方面没有了
      

  6.   

    有继承TabActivity 方便加你QQ聊吗?
      

  7.   

    activity是继承TabTabActivity,所以你一直用tabhost报错了,,,
      

  8.   

    我试了一下把那句.setContent(new Intent(Gdhuidan.this,Gddaichuli.class))); 改成.setContent(new Intent(this,MainActivity.class)));在那选项卡中跳转到MainActivity.class这里是正常的,只是跳转到Gddaichuli.class这个页面才出错,但是在其他非选项卡页面直接跳转到Gddaichuli.class也是正常的