Classe Principal:
package com.example.androidtablayout;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
public class AndroidTabLayoutActivity extends TabActivity implements OnTabChangeListener {
/** 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 Photos
TabSpec photospec = tabHost.newTabSpec("Photos");
photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
Intent photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);
// Tab for Songs
TabSpec songspec = tabHost.newTabSpec("Songs");
// setting Title and Icon for the Tab
songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
Intent songsIntent = new Intent(this, SongsActivity.class);
songspec.setContent(songsIntent);
// Tab for Videos
TabSpec videospec = tabHost.newTabSpec("Videos");
videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
Intent videosIntent = new Intent(this, VideosActivity.class);
videospec.setContent(videosIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(photospec); // Adding photos tab
tabHost.addTab(songspec); // Adding songs tab
tabHost.addTab(videospec); // Adding videos tab
}
public void onTabChanged(String tabId) {
// if (tabId.equals("tab_test2")) {
if (tabId.equals("Videos")) {
Activity currentActivity = getCurrentActivity();
// aqui recupere o valor do singleton
MySingleton mDados = MySingleton.getInstance ();
int i = mDados.getMyInt();
String s = mDados.getMyString();
Toast.makeText(getBaseContext(), s, Toast.LENGTH_LONG).show();
}
}
}
Primeira Aba:
package com.example.androidtablayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class PhotosActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photos_layout);
final EditText nome = (EditText) findViewById(R.id.edtNome);
Button Salvar = (Button) findViewById(R.id.btnSalvar);
MySingleton mDados = MySingleton.getInstance ();
mDados.setMyInt(100);
mDados.setMyString("Testando classe");
// String s = nome.getText().toString();
// mDados.setMyString(s);
Salvar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String valor = nome.getText().toString();
Toast.makeText(getBaseContext(), valor, Toast.LENGTH_LONG).show();
}
});
Segunda Aba:
package com.example.androidtablayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SongsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.songs_layout);
final EditText Nome = (EditText) findViewById(R.id.edtNome);
Button Salvar = (Button) findViewById(R.id.btnSalvar);
Salvar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String nome = Nome.getText().toString();
Toast.makeText(getBaseContext(), nome, Toast.LENGTH_LONG).show();
}
});
}
}
Terceira Aba:
package com.example.androidtablayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class VideosActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos_layout);
final EditText Nome = (EditText) findViewById(R.id.edtNome);
Button Salvar = (Button) findViewById(R.id.btnSalvar);
Salvar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// String nome = Nome.getText().toString();
// Toast.makeText(getBaseContext(), "teste", Toast.LENGTH_LONG).show();
MySingleton mDados = MySingleton.getInstance ();
int i = mDados.getMyInt();
String s = mDados.getMyString();
Toast.makeText(getBaseContext(), s, Toast.LENGTH_LONG).show();
}
});
}
}
Att,
Frederico Brigatte
De: androidbrasil-dev@googlegroups.com [mailto:androidbrasil-dev@googlegroups.com] Em nome de Maicon Strey
Enviada em: quinta-feira, 8 de agosto de 2013 11:20
Para: androidbrasil-dev@googlegroups.com
Assunto: Re: [androidbrasil-dev] Abas
Cara,
tu ta puxando isso da tela né? tu preencheu algo nesse campo lá na tela?
Maicon Strey
Novo Hamburgo - RS - Brasil
------------------
------------------
Linux user: #525086
2013/8/8 Fred <frederico.brigatte@gmail.com>
Ta vazio mesmo, não entendo pq acontece isso. Se uso constante funciona.
Att,
Frederico Brigatte
De: androidbrasil-dev@googlegroups.com [mailto:androidbrasil-dev@googlegroups.com] Em nome de Maicon Strey
Enviada em: quinta-feira, 8 de agosto de 2013 11:16
Para: androidbrasil-dev@googlegroups.com
Assunto: Re: [androidbrasil-dev] Abas
Não mostra nada de erros ou não mostra nada no debug do campo?
se for pros dois ta resolvido. teu campo está vazio!
Maicon Strey
Novo Hamburgo - RS - Brasil
------------------
------------------
Linux user: #525086
2013/8/8 Fred <frederico.brigatte@gmail.com>
Já, não mostra nada, absolutamente nada
Att,
Frederico Brigatte
De: androidbrasil-dev@googlegroups.com [mailto:androidbrasil-dev@googlegroups.com] Em nome de Maicon Strey
Enviada em: quinta-feira, 8 de agosto de 2013 11:10
Para: androidbrasil-dev@googlegroups.com
Assunto: Re: [androidbrasil-dev] Abas
olhou o log?
está dando algum erro no log?
tentou debugar manualmente?
mandando exibir nome.getText().toString() direto no log exibe algo?
Maicon Strey
Novo Hamburgo - RS - Brasil
------------------
------------------
Linux user: #525086
2013/8/8 Fred <frederico.brigatte@gmail.com>
Maicon, dessa vez NÃO SEI mesmo o que ta acontecendo.
Att,
Frederico Brigatte
De: androidbrasil-dev@googlegroups.com [mailto:androidbrasil-dev@googlegroups.com] Em nome de Maicon Strey
Enviada em: quinta-feira, 8 de agosto de 2013 11:01
Para: androidbrasil-dev@googlegroups.com
Assunto: Re: [androidbrasil-dev] Abas
Fred,
1) não é todo problema que alguém tem uma solução fácil
2) talvez tu tenha te queimado com o pessoal e agora não querem te ajudar mesmo.
Nos dois casos continua estudando o problema.
Maicon Strey
Novo Hamburgo - RS - Brasil
------------------
------------------
Linux user: #525086
2013/8/8 Fred <frederico.brigatte@gmail.com>
Eu PESQUISEI, ENCONTREI, ADAPTEI o projeto, e esta acontecendo algo estranho. Agora que consegui fazer com meu próprio esforço e coloco aqui o “erro”, NINGUÉM ajuda? Eu fiz agora, não estou pedindo nenhum exemplo.
Att,
Frederico Brigatte
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário