私は別のとげのある小さな問題に遭遇しました。
タブ付きのアプリを書いていますが、画面上部にテキストボックス (EditText) があり、任意のタブからテキスト データを受信できるようにしたいと考えています。各タブには独自のアクティビティとレイアウトがあるため、これを実現するのは困難です。
私は使用できるようにしたい:
editText1.setText("Hello World");//sample text
任意のタブ/アクティビティから。
あるレイアウトからテキストボックスを公開してテキストを受信できるようにする方法を知っている人はいますか?
私はTabActivityを使用しています。はい、非推奨であることは知っていますが、これはタブを使用した最初のアプリであるため、フラグメントよりも習得が簡単です。それらが私の問題に対する答えでない限り、次回はそれらを試してみます。
よし、新パーツ。
package com.epsilonitsystems.epecsandroid;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
import android.view.Menu;
import android.speech.tts.TextToSpeech;
public class MainActivity extends TabActivity {
public EditText editText1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1 = (EditText) findViewById(R.id.editText1);
TabHost tabHost = getTabHost();
// Tab for Core
TabSpec corespec = tabHost.newTabSpec("Core");
corespec.setIndicator("", getResources().getDrawable(R.drawable.ic_i));
Intent coreIntent = new Intent(this, CoreActivity.class);
corespec.setContent(coreIntent);
// Tab for Drink
TabSpec drinkspec = tabHost.newTabSpec("Drink");
drinkspec.setIndicator("", getResources().getDrawable(R.drawable.ic_drink));
Intent drinkIntent = new Intent(this, DrinkActivity.class);
drinkspec.setContent(drinkIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(corespec); // Adding Core tab
tabHost.addTab(drinkspec); // Adding Drink tab
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
それがメイン アクティビティです。コア アクティビティだけを表示します。コア アクティビティが機能するようになると、それらはすべて同じになるからです。
package com.epsilonitsystems.epecsandroid;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.speech.tts.TextToSpeech;
public class CoreActivity extends Activity {
private TextToSpeech mTts;
// This code can be any value you want, its just a checksum.
private static final int MY_DATA_CHECK_CODE = 1234;
EditText editText1;
String Spch,Str;
ImageButton imageButton1,imageButton2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.core_layout);
//button1 = (Button) findViewById(R.id.button1);
editText1 = (EditText) findViewById(R.id.editText1);
mTts = new TextToSpeech(this, null);
}
public void onimageButton1Click(View view) {
//mTts.speak("I",TextToSpeech.QUEUE_FLUSH,null);
//Spch=editText1.toString();
//Spch=Spch+"I ";
editText1.setText("Hello World");
}
}//Activity End
私はまだ新しいユーザーなので、スクリーンショットを投稿できません。申し訳ありません。
アイデアはありますか?