タブダイアログの下に複数のアクティビティを作成したかったのです。しかし、問題は、ボタンを押すと、次のエラーが表示されることです: and apps from base.
06-18 19:57:06.444 E / AndroidRuntime (1061): $ android.view.WindowManager BadTokenException: ウィンドウを追加できません - トークン $ android.app.LocalActivityManager ローカル アクティビティ レコード @ 44f6a3e8 が無効です。アクティビティは実行されていますか?
プログラムはshowDialog(0)で、正確です。長い間検索しましたが、残念ながら答えを見つけることができませんでした。助けてください。複数の Tabactivitiy ダイアログを表示するにはどうすればよいですか。?
タブ アクティビティ :
public class main extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tb = getTabHost();
TabHost.TabSpec spec;
Intent inten;
//tourism tab
inten = new Intent().setClass(this, tum_yemekler.class);
spec = tb.newTabSpec("tab1").setIndicator("Tüm Yemekler",res.getDrawable(R.drawable.hotel))
.setContent(inten);
tb.addTab(spec);
//hotel tab
inten = new Intent().setClass(this, contactgroupeinkaufliste.class);
spec = tb.newTabSpec("tab2").setIndicator("Yemek Bul",res.getDrawable(R.drawable.wisata))
.setContent(inten);
tb.addTab(spec);
//mall tab
inten = new Intent().setClass(this, gunun_menusu.class);
spec = tb.newTabSpec("tab3").setIndicator("Günün Menüsü",res.getDrawable(R.drawable.mall))
.setContent(inten);
tb.addTab(spec);
//restourant tab
inten = new Intent().setClass(this, yardim.class);
spec = tb.newTabSpec("tab4").setIndicator("Yardım",res.getDrawable(R.drawable.restoran))
.setContent(inten);
tb.addTab(spec);
tb.setCurrentTab(0);
}
}
アクティビティ グループ:
import java.util.ArrayList;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
public class contactgroupeinkaufliste extends ActivityGroup {
View rootView;
public static contactgroupeinkaufliste ContactGroupEinkaufliste_;
sayilar ddsayilar ;
private ArrayList<View> history1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history1 = new ArrayList<View>();
ContactGroupEinkaufliste_ = this;
View view = getLocalActivityManager().startActivity("CitiesActivity", new
Intent(this,secimliyemek_main.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
// Replace the view of this ActivityGroup
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
history1.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
if(history1.size() > 0) {
history1.remove(history1.size()-1);
if(history1.size()<=0){
finish();
}else{
setContentView(history1.get(history1.size()-1));
}
}else {
finish();
}
}
@Override
public void onBackPressed() {
contactgroupeinkaufliste.ContactGroupEinkaufliste_.back();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK){
contactgroupeinkaufliste.ContactGroupEinkaufliste_.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
アクティビティ
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class secimliyemek_main extends Activity {
public static secimliyemek_main secimliyemek_main_;
public static sayilar sayilarr;
public static String baslik ;
public static bilgideposu arraylistesi;
public static String [] baharat ;
public static String [] option;
public static boolean[] _selections ;
public static LinkedList<String> malzemeler =new LinkedList<String>();
protected Button Button_sebzeler;
protected Button Button_baharatlar;
protected Button Button_baklagiller;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.secimliyemek_main);
Button_sebzeler = ( Button ) findViewById( R.id.sebzeler );
Button_sebzeler.setOnClickListener( new ButtonClickHandler_sebzeler() );
Button_baharatlar = ( Button ) findViewById( R.id.baharat );
Button_baharatlar.setOnClickListener( new ButtonClickHandler_baharat() );
Button_baklagiller = ( Button ) findViewById( R.id.baklagil);
Button_baklagiller.setOnClickListener( new ButtonClickHandler_baklagiller() );
Button yemek_bul =(Button)findViewById(R.id.yemek_bul);
yemek_bul.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
View view1 = contactgroupeinkaufliste.ContactGroupEinkaufliste_.getLocalActivityManager().startActivity("secimliyemek_liste",
new Intent("com.faqih.tutorialtab.SECIMLIYEMEK_LISTE")
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
// Replace the view of this ActivityGroup
contactgroupeinkaufliste.ContactGroupEinkaufliste_.replaceView(view1);
}
});
}
public class ButtonClickHandler_sebzeler implements View.OnClickListener {
public void onClick( View view ) {
option =arraylistesi.sebzeler;
baslik = "Sebzeler";
boolean[] _selectionss = new boolean[ option.length ];
_selections=_selectionss;
Button_sebzeler = ( Button ) findViewById( R.id.sebzeler );
//-------------- error comes from here -----------------????
showDialog(0);
}
}
public class ButtonClickHandler_baharat implements View.OnClickListener {
public void onClick( View view ) {
option =arraylistesi.baharatlar;
baslik = "Baharatlar";
boolean[] _selectionss = new boolean[ option.length ];
_selections=_selectionss;
Button_baharatlar = ( Button ) findViewById( R.id.baharat );
showDialog(2);
}
}
public class ButtonClickHandler_baklagiller implements View.OnClickListener {
public void onClick( View view ) {
option =arraylistesi.baklagiller;
baslik = "Baklagiller";
boolean[] _selectionss = new boolean[ option.length ];
_selections=_selectionss;
Button_baklagiller = ( Button ) findViewById( R.id.baklagil );
showDialog(3);
}
}
@Override
protected Dialog onCreateDialog( int id )
{
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("Enter Holla message");
EditText hollaMessage = new EditText(this);
dialog.setView(hollaMessage);
dialog.setCancelable(false);
dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
List result = new ArrayList();
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dismissDialog(0); } });
AlertDialog alert = dialog.create();
return alert;
}
public class DialogSelectionClickHandler implements DialogInterface.OnMultiChoiceClickListener
{
public void onClick( DialogInterface dialog, int clicked, boolean selected )
{
printSelectedPlanets(selected,clicked);
Toast.makeText(secimliyemek_main.this, clicked +" "+selected, Toast.LENGTH_SHORT).show();
}
}
public class DialogButtonClickHandler implements DialogInterface.OnClickListener
{
public void onClick( DialogInterface dialog, int clicked )
{
switch( clicked )
{
case DialogInterface.BUTTON_POSITIVE:
closeContextMenu();
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
}
}
protected void printSelectedPlanets(boolean clickedv, int clickedsv){
if(clickedv == true){
malzemeler.add(option[ clickedsv ]);
Toast.makeText(secimliyemek_main.this, "eklenen: "+option[ clickedsv ] , Toast.LENGTH_SHORT).show();
}
if(clickedv== false){
malzemeler.remove(option[ clickedsv]);
Toast.makeText(secimliyemek_main.this, "cikarilan: "+option[ clickedsv ] , Toast.LENGTH_SHORT).show();
}
}
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK){
contactgroupeinkaufliste.ContactGroupEinkaufliste_. back();
return true;
}
return super.onKeyDown(keyCode, event);
}
}