-1

動的に作成されたタブを持つ tabHost ウィジェットがあります。新しく作成された各タブには、いくつかのビュー (textView、listView など) を持つ相対的なレイアウトがあります。

私の質問は、これらのビューにアクセスする方法と、そこに新しいコンテンツを追加する方法です。ID やタグを設定してみましたが、うまくいきませんでした。

   public class Main extends Activity {

    @Override
    public void onCreate(Bundle icicle) {
       super.onCreate(icicle);
       setContentView(R.layout.main);

       final TabHost tabs=(TabHost)findViewById(R.id.tabhost);
       tabs.setup();   
       TabHost.TabSpec spec=tabs.newTabSpec("buttontab");
       spec.setContent(R.id.form);
       spec.setIndicator("Search-form");
       tabs.addTab(spec);

       Button btn=(Button)tabs.getCurrentView().findViewById(R.id.buttontab);

       btn.setOnClickListener(new View.OnClickListener() {



           public void onClick(View view) {
                final TabHost.TabSpec spec=tabs.newTabSpec("tag1");        
                spec.setContent(new TabHost.TabContentFactory() {
                public View createTabContent(String tag) 
                {
                   // Creating a new RelativeLayout
               RelativeLayout relativeLayout = new RelativeLayout(Main.this);
                   // Defining the RelativeLayout layout parameters.
                   RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.FILL_PARENT);


                           TextView t = new TextView(Main.this);
                           // t.setId(12); //This dosen't work
                           t.setText("Searching in progress. Please wait...");

                           ListView resultsList = new ListView(Main.this);
                           //Here: array adapter etc

                          // Adding the TextView to the RelativeLayout as a child
                          relativeLayout.addView(t);
                          relativeLayout.addView(resultsList);

                          return relativeLayout;

                       }
                   });
                   spec.setIndicator("Tab with results");
                   tabs.addTab(spec);
                   new GetData(Main.this).execute();      
                }
            });
     }



     public void appendResultsToViews(String result)
     {
           //Here i need to access TextView from tab with specific tag and append results to TextView, which was created dynamically earlier
     }

ご協力ありがとうございました。

4

1 に答える 1