0down votefavorite share [g+]share [fb]share [tw]
I'm an Android noob and I'm writing an application that has 3 tabs with buttons added to the tabs dynamically in code. This works fine with API 11 or up, but not with any lower API. I don't get an error message with a lower API, the buttons just don't display. However, I can click/touch just under the tab title and the button will fire properly. My code is below. Any ideas? Thanks! <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabHost android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/Beginning" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> <LinearLayout android:id="@+id/Intermediate" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> <LinearLayout android:id="@+id/Advanced" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </LinearLayout> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabhost = (TabHost) findViewById(R.id.tabhost); tabhost.setup(); TabSpec spec_beg = tabhost.newTabSpec("Beginning"); spec_beg.setContent(R.id.Beginning); TextView txtTabInfo = new TextView(this); txtTabInfo.setText("JUST STARTING"); Typeface font = Typeface.createFromAsset(getAssets(), "danielbd.ttf"); txtTabInfo.setTypeface(font); txtTabInfo.setGravity(Gravity.CENTER); txtTabInfo.setHeight(50); txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A")); txtTabInfo.setTextColor(Color.parseColor("#262405")); spec_beg.setIndicator(txtTabInfo); TabSpec spec_int = tabhost.newTabSpec("Intermediate"); spec_int.setContent(R.id.Intermediate); txtTabInfo = new TextView(this); txtTabInfo.setText("GETTING THERE"); txtTabInfo.setTypeface(font); txtTabInfo.setGravity(Gravity.CENTER); txtTabInfo.setHeight(50); txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A")); txtTabInfo.setTextColor(Color.parseColor("#262405")); spec_int.setIndicator(txtTabInfo); TabSpec spec_adv = tabhost.newTabSpec("Advanced"); spec_adv.setContent(R.id.Advanced); txtTabInfo = new TextView(this); txtTabInfo.setText("REALLY GOOD"); txtTabInfo.setTypeface(font); txtTabInfo.setGravity(Gravity.CENTER); txtTabInfo.setHeight(50); txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A")); txtTabInfo.setTextColor(Color.parseColor("#262405")); spec_adv.setIndicator(txtTabInfo); // get data from database, create buttons and name them SQLData myTable = new SQLData(this); myTable.open(); Cursor c = myTable.getallData(); int iRow = c.getColumnIndex(KEY_ROWID); int iName = c.getColumnIndex(KEY_STITCHNAME); int iLevel = c.getColumnIndex(KEY_LEVEL); // create the buttons for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { final String RowNum = c.getString(iRow); String StitchName = c.getString(iName); String StitchLevel = c.getString(iLevel); Button button = new Button(this); button.setText(StitchName); button.setHeight(20); button.setTextColor(Color.BLACK); button.setBackgroundColor(Color.parseColor("#A89E0A")); button.setHighlightColor(Color.WHITE); button.setTypeface(font); button.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Intent choice = new Intent(getApplicationContext(), com.KnitCard.project.KnitCard.class); Bundle dataBundle = new Bundle(); dataBundle.putString("RowID", RowNum); choice.putExtras(dataBundle); try{ startActivity(choice); }catch(Exception e){ Dialog d = new Dialog(getApplicationContext()); d.setTitle("Boo!"); TextView tv = new TextView(getApplicationContext()); tv.setText(e.toString()); d.setContentView(tv); d.show(); }finally{ } } }); LinearLayout lbeg = (LinearLayout)findViewById(R.id.Beginning); LinearLayout lint = (LinearLayout)findViewById(R.id.Intermediate); LinearLayout ladv = (LinearLayout)findViewById(R.id.Advanced); if (StitchLevel.equals("Beginning")) lbeg.addView(button); else if (StitchLevel.equals("Intermediate")) lint.addView(button); else if (StitchLevel.equals("Advanced")) ladv.addView(button); } tabhost.addTab(spec_beg); tabhost.addTab(spec_int); tabhost.addTab(spec_adv); myTable.close(); } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en