tags:

views:

91

answers:

3

Hi,

In my application, i'm creating dynamic tabs.Inside framelayout I've created a edittext.For each tab i create content of tab will be edittext. When i type in editext of one tab and later if i create a new tab and when i switch between these tabs, it shows the content of editext as empty. I hope anybody will understand my problem. Sorry for my english. Help me.

With regards Kavya

A: 

You need to store the value of the EditText in some manner. A good way is to show tab content through an activity and use this method to store instance state.

Sameer Segal
I tried created activity for each tabs. It was throwing exceptions.
I'm doing everything in the same activity. OnSaveInstanceState() method gets called when user leaves the activity.But I'm in same activity.
Paste the errors of your program (multiple activity mode). Have you registered the activities in the manifest?
Sameer Segal
A: 

I don't want to create a separate activity for each tab.I'l explain along with the code.

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TabHost tabs = (TabHost)this.findViewById(R.id.tabs);
      tabs.setup();
        TabHost.TabSpec spec1=tabs.newTabSpec(f);
   spec1.setContent(R.id.content1);
   spec1.setIndicator(f);
tabs.addTab(spec1);
tabs.setCurrentTab(i);
list.add(spec1);  
i++;
    Addbtn.setOnClickListener(new OnClickListener()
{
    @Override
   public void onClick(View arg0) 
  {
          final TabHost tabs = (TabHost)this.findViewById(R.id.tabs);
      tabs.setup();
          TabHost.TabSpec spec1=tabs.newTabSpec(f);
     spec1.setContent(R.id.content1);
     spec1.setIndicator(f);
    tabs.addTab(spec1);
    tabs.setCurrentTab(i);
    list.add(spec1);  
    i++;
    });

Default one tab will be there. here content of tab is edittext. When i click on button new tab will be created. problem is with the content of tab. In default tab if i type in edittext, and create a new tab and switch to the default tab the content of default would be lost.

Please help me. Sorry for my english.

A: 

You can use an EditorActionListener, which is called when someone presses the 'Enter' or IME_ACTION key to store the values of your EditText.

Instead of doing spec1.setContent(R.id.content1);, create an EditText dynamically (new EditText(context)) and put a number (Tab Number) as a Tag, which you can retrieve and store in a List.

mEditText.setOnEditorActionListener(new OnEditorActionListener() {

                        @Override
                        public boolean onEditorAction(TextView v, int actionId,
                                KeyEvent event) {

                                       int position = (int) v.getTag();

                                       String s = ((EditText) v).getText()
                                       // store in an object

                      return false;
       }
});

Not sure how you will retrieve this without launching subActivities!

Sameer Segal
I'm facing one more problem.I created a menu.In menu option how can i access the current tab?