この問題を解決するには助けが必要です。私のコーディングは最初のレイアウトでしか機能せず、2 番目のレイアウトでは機能しないという問題。
これは私のタブ xml レイアウトです
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
これは私のタブJavaファイルです
package watresystem.com;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class WatersystemActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Output
TabSpec outputspec = tabHost.newTabSpec("Output");
// setting Title and Icon for the Tab
outputspec.setIndicator("Output", getResources().getDrawable(R.drawable.icon_output_tab));
Intent outputIntent = new Intent(this, OutputActivity.class);
outputspec.setContent(outputIntent);
// Tab for Input
TabSpec inputspec = tabHost.newTabSpec("Input");
inputspec.setIndicator("Input", getResources().getDrawable(R.drawable.icon_input_tab));
Intent inputIntent = new Intent(this, InputActivity.class);
inputspec.setContent(inputIntent);
// Tab for Time & Date
TabSpec timespec = tabHost.newTabSpec("Time");
timespec.setIndicator("Time", getResources().getDrawable(R.drawable.icon_time_tab));
Intent timeIntent = new Intent(this, TimeActivity.class);
timespec.setContent(timeIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(outputspec); // Adding output tab
tabHost.addTab(inputspec); // Adding input tab
tabHost.addTab(timespec); // Adding time tab
}
}
タブレイアウトの入力ボタンの私のJavaコード
package watresystem.com;
import android.app.Activity;
import android.os.Bundle;
import ioio.lib.api.DigitalInput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.AbstractIOIOActivity;
import android.widget.TextView;
public class InputActivity extends AbstractIOIOActivity {
private final int BUTTON1_PIN = 37;
private final int BUTTON2_PIN = 32;
private final int BUTTON3_PIN = 33;
private TextView mBtn1TextView;
private TextView mBtn2TextView;
private TextView mBtn3TextView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input_layout);
mBtn1TextView = (TextView) findViewById(R.id.btn1TextView);
mBtn2TextView = (TextView) findViewById(R.id.btn2TextView);
mBtn3TextView = (TextView) findViewById(R.id.btn3TextView);
}
class IOIOThread extends AbstractIOIOActivity.IOIOThread {
private DigitalInput mButton1;
private DigitalInput mButton2;
private DigitalInput mButton3;
@Override
public void setup() throws ConnectionLostException {
try {
mButton1 = ioio_.openDigitalInput(BUTTON1_PIN, DigitalInput.Spec.Mode.PULL_UP);
mButton2 = ioio_.openDigitalInput(BUTTON2_PIN, DigitalInput.Spec.Mode.PULL_UP);
mButton3 = ioio_.openDigitalInput(BUTTON3_PIN, DigitalInput.Spec.Mode.PULL_UP);
} catch (ConnectionLostException e) {
throw e;
}
}
@Override
public void loop() throws ConnectionLostException {
try {
String button1txt;
String button2txt;
String button3txt;
final boolean reading1 = mButton1.read();
final boolean reading2 = mButton2.read();
final boolean reading3 = mButton3.read();
if (!reading1) {
button1txt = getString(R.string.button1) + " active!";
} else {
button1txt = getString(R.string.button1);
}
if (!reading2) {
button2txt = getString(R.string.button2) + " active!";
} else {
button2txt = getString(R.string.button2);
}
if (!reading3) {
button3txt = getString(R.string.button3) + " active!";
} else {
button3txt = getString(R.string.button3);
}
setText(button1txt, button2txt, button3txt);
sleep(10);
} catch (InterruptedException e) {
ioio_.disconnect();
} catch (ConnectionLostException e) {
throw e;
}
}
}
@Override
protected AbstractIOIOActivity.IOIOThread createIOIOThread() {
return new IOIOThread();
}
private void setText(final String str1, final String str2, final String str3) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mBtn1TextView.setText(str1);
mBtn2TextView.setText(str2);
mBtn3TextView.setText(str3);
}
});
}
}
入力ボタンの私のxmlレイアウト
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<!-- Screen Design for Input -->
<TextView
android:id="@+id/btn1TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button1"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/btn2TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button2"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/btn3TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button3"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>