使用TabLayout时无法通过套接字传递数据

时间:2012-08-01 04:32:39

标签: android serversocket android-tabs

最初,我只有一个基本页面,其中不包含任何tablayout,并且它运行良好。插入的数据已通过套接字。

现在,我正在使用tablayout,它不会传递数据。发生了什么事?

这是我的活动,包括套接字:

commandline = commandline + "[" + id+"]";

Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;

 try {           
      socket = new Socket("xxx.xx.xxx.xx", 2000);
      dataOutputStream = new DataOutputStream(socket.getOutputStream());
      dataInputStream = new DataInputStream(socket.getInputStream());
      dataOutputStream.writeBytes(commandline);
      //dataOutputStream.writeChars("Kacang Lupakan Kulit");

  } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      tv.setText(readStackTrace(e));
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

      //tv.setText(readStackTrace(e));
  } finally{

  }

  if (dataOutputStream != null){
      try {
          dataOutputStream.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          //tv.setText(readStackTrace(e));
      }
  }

  if (dataInputStream != null){
      try {
          dataInputStream.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          //tv.setText(readStackTrace(e));
      }
  }


  if (socket != null){
      try {
          socket.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          // tv.setText(readStackTrace(e));
      }
  }

这是我的mainActivity,我声明了标签:

public class MainActivity extends TabActivity {
private TabHost aTab;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);        

    TabHost tabHost = getTabHost();

    TabSpec report = tabHost.newTabSpec("Report");
    report.setIndicator("Report", getResources().getDrawable(R.drawable.report_01));
    Intent reportIntent = new Intent(this, ReportActivity.class);
    report.setContent(reportIntent);

    TabSpec profile = tabHost.newTabSpec("Profile");
    profile.setIndicator("Profile", getResources().getDrawable(R.drawable.profile_01));
    Intent profileIntent = new Intent(this, ProfileActivity.class);
    profile.setContent(profileIntent);


    TabSpec about = tabHost.newTabSpec("About");
    about.setIndicator("About", getResources().getDrawable(R.drawable.about_01));
    Intent aboutIntent = new Intent(this, AboutActivity.class);
    about.setContent(aboutIntent);


    // Adding all TabSpec to TabHost
    tabHost.addTab(report); 
    tabHost.addTab(profile);
    tabHost.addTab(about); 
    }       
}

需要提交的数据位于报告标签中。

**这与使用TabLayout之前使用的代码相同,但确实传递了数据。

有人知道吗?请。

0 个答案:

没有答案