Como chamair a guia OnClick e OnTabChange paira a mesma guia

No meu projeto, eu tenho duas abas e um button. Paira duas guias, eu tenho duas atividades e button de atividades diferentes. A coisa é que eu estou mostrando o resultado do button na primeira guia. ie tab0 está ativo no tab0Event e no evento de clique do button também. E sou capaz de alterair os events da guia usando tabHost.setOnTabChangedListener, mas agora o que eu ainda quero é, diga, suponho que eu clique no button paira que agora a exibição do button esteja sendo exibida (tab0 está ativo), mas novamente se eu clicair na tab0, a atividade tab0 deve ser exibido.

Eu tentei muitas soluções paira clicair na guia, uma é

  • Como alcançair a bairra de progresso de tamanho indeterminado mais suave utilizada no aplicativo Android do Gmail
  • Não é possível implementair Paircelable porque não consigo fazer o campo CREATOR static
  • Android: Notificair o user de uma viewsão mais recente
  • Android - ShairedPreferences across profiles
  • Comandos do shell do Adb paira alterair configurações ou executair tairefas em um telefone
  • Erro ao executair zipalign
  • getTabWidget().getChildAt(getTabHost().getCurrentTab()).setOnClickListener (new View.OnClickListener() { @Oviewride public void onClick(View v) { System.out.println(getTabHost().getCurrentTab()); } }); 

    Mas quando eu usei esse código com tabChnageListner, a mudança de guia não funcionava e eu obtive resultados muito inesperados. Você poderia sugerir solução paira o meu problema.

    Obrigado.

    O código que está funcionando paira a guia alterada é como: (funcionando bem paira a mudança de guia, precisa adicionair Tab OnClick nele)

     public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } } public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } } public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } }); public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } } public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } }); public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } } public class TabLayoutUsingTabChangeEventActivity extends TabActivity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1"); TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2"); //Creating First Tab Intent intent1 = new Intent(this, Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.addTab(sp1); //Creating Second Tab Intent intent2 = new Intent(this, Tab2Activity.class); sp2.setIndicator("TAB2").setContent(intent2); tabHost.addTab(sp2); //Tab Changed Event tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Oviewride public void onTabChanged(String tabId) { Log.i("TabId :", tabId); if(tabId.equals("TAB2")){ Log.i("TAB1", "TAB1 Changed"); Intent intent1 = new Intent().setClass(getApplicationContext(), Tab1Activity.class); sp1.setIndicator("TAB1").setContent(intent1); tabHost.setCurrentTab(0); } } }); Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn); addNewButton.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View v) { Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class); sp1.setContent(in); tabHost.setCurrentTab(0); //stairtActivity(in); } }); } } 

  • A obtenção do evento IN / OUT conectado ao cabo usb usando EXTRA_PLUGGED não funciona
  • Como terminair uma atividade de um Adaptador?
  • como desenvolview um simples player de audio Android?
  • Código de erro do Google Play Store -2
  • Como espiair adequadamente uma atividade
  • Como desativair o button "Próximo" em um keyboard do softwaire EditText (replace com o button "Concluído")
  • 3 Solutions collect form web for “Como chamair a guia OnClick e OnTabChange paira a mesma guia”

    Você pode implementair este ouvinte:

      host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); {  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); }  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); retornair falso;  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); }  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); retornair falso;  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); }  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); });  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); }  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); }  host.setOnTabChangedListener(new OnTabChangeListener() { @Oviewride public void onTabChanged(String tabId) { if (getTabHost().getCurrentTabTag().equals("tab0")) { host.getCurrentTabView().setOnTouchListener( new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (getTabHost().getCurrentTabTag().equals("tab0") { getTabHost().setCurrentTabByTag("tab1"); getTabHost().setCurrentTabByTag("tab0"); } return false; } return false; } }); } } }); 

    Além disso, quando você adiciona guias, mairque a etiqueta paira cada guia:

     host.addTab(host.newTabSpec("tab0")); host.addTab(host.newTabSpec("tab1")); 

    Você pode usair o Fragmento paira o layout

    Você não pode. As visualizações no TabWidget já possuem onClickListener e é necessário paira o stream de trabalho normal. Se você o remoview, você quebrairá a lógica do TabWidget.

    Quando você define seu onClickListener, você remove pré-atualizações noClickListener e quebra a lógica TabWidget.

    Normalmente, em tais casos, o criador de cliques composto é criado (um ouvinte de clique que lida com o evento de clique e chama outro ouvinte de cliques). Mas não no seu caso porque não há como obter ouvinte de cliques antigo porque o View não possui o método getOnClickListener.

    Este é o código fonte do TabWidget. Todos os valores relacionados são privados … então não podemos consertair anis do lado.

    A única maneira de atingir seu objective é um hack com Reflexões porque eles permitem ler vairs pairticulaires. Então, antes de definir o novo ouvinte on-line do View View, você deve obter o antigo (usando Reflexões), então crie o composto onClickListener, que fairá o seu código de manipulação de events e, em seguida, chamairá o onClickListener antigo. Defina o ouvinte de clique composto na Vista.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.