Android 使用TabLayout时,无法通过套接字传递数据
最初,我只有一个基本页面,其中不包含任何Android 使用TabLayout时,无法通过套接字传递数据,android,serversocket,android-tabs,Android,Serversocket,Android Tabs,最初,我只有一个基本页面,其中不包含任何tablayout,它工作得非常好。插入的数据已通过套接字 现在,我使用的是tablayout,它不会传递数据。发生了什么事 这是我的活动,包括套接字: commandline = commandline + "[" + id+"]"; Socket socket = null; DataOutputStream dataOutputStream = null; DataInputStream dataInputStream = null; try
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));
}
}
这是我声明选项卡的主要活动:
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
之前使用的代码相同,它会传递数据
有人知道这件事吗?求你了