Note that there are some explanatory texts on larger screens.

plurals
  1. POTab and file display
    primarykey
    data
    text
    <p>I was wondering if there is a simple way in which I can get my tabs to display a file that I have in my layout folder. I've thought about just using a webview to display but is there any better way, just curious. Here's my code below.</p> <pre><code> import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class TabContentActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textview = new TextView(this); textview.setText(getIntent().getStringExtra("content")); setContentView(textview); } } Layout &lt;!-- language: xml --&gt; &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/tabcontainer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="48dp" android:background="#000" android:gravity="center_horizontal" &gt; &lt;/TabWidget&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fadeScrollbars="false" android:fadingEdge="none" android:scrollbars="@null" &gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab" android:layout_width="wrap_content" android:layout_height="48dp" android:layout_gravity="left" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/tabLabel" android:layout_width="fill_parent" android:layout_height="43dp" android:gravity="center_vertical|center_horizontal" android:textColor="#FFF" android:textSize="14sp" /&gt; &lt;TextView android:id="@+id/tabSelectedDivider" android:layout_width="fill_parent" android:layout_height="5dp" android:layout_alignParentBottom="true" android:background="#3366CC" android:visibility="gone" /&gt; &lt;TextView android:id="@+id/tabDivider" android:layout_width="fill_parent" android:layout_height="2dp" android:layout_alignParentBottom="true" android:background="#3366CC" /&gt; &lt;TextView android:id="@+id/tabSplitter" android:layout_width="1px" android:layout_height="23dp" android:layout_alignParentRight="true" android:layout_marginTop="10dp" android:background="#333" /&gt; &lt;/RelativeLayout&gt; import android.app.TabActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; import android.widget.TextView; public class TabTutorialActivity extends TabActivity { // Divide 1.0 by # of tabs needed // In this case: 1.0/2 =&gt; 0.5 private static final LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); private static TabHost tabHost; private static TabHost.TabSpec spec; private static Intent intent; private static LayoutInflater inflater; private View tab; private TextView label; private TextView divider; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get inflator so we can start creating the custom view for tab inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Get tab manager tabHost = getTabHost(); // This converts the custom tab view we created and injects it into the tab widget tab = inflater.inflate(R.layout.tab, getTabWidget(), false); // Mainly used to set the weight on the tab so each is equally wide tab.setLayoutParams(params); // Add some text to the tab label = (TextView) tab.findViewById(R.id.tabLabel); label.setText("Repition Counter"); // Show a thick line under the selected tab (there are many ways to show // which tab is selected, I chose this) divider = (TextView) tab.findViewById(R.id.tabSelectedDivider); divider.setVisibility(View.VISIBLE); // Intent whose generated content will be added to the tab content area intent = new Intent(TabTutorialActivity.this, TabContentActivity.class); // Just some data for the tab content activity to use (just for demonstrating changing content) intent.putExtra("content", "Content for HOME"); // Finalize the tabs specification spec = tabHost.newTabSpec("home").setIndicator(tab).setContent(intent); // Add the tab to the tab manager tabHost.addTab(spec); // Add another tab tab = inflater.inflate(R.layout.tab, getTabWidget(), false); tab.setLayoutParams(params); label = (TextView) tab.findViewById(R.id.tabLabel); label.setText("BMI"); intent = new Intent(TabTutorialActivity.this, TabContentActivity.class); intent.putExtra("content", "Content for USERS"); spec = tabHost.newTabSpec("users").setIndicator(tab).setContent(intent); tabHost.addTab(spec); // Listener to detect when a tab has changed. I added this just to show // how you can change UI to emphasize the selected tab tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tag) { // reset some styles clearTabStyles(); View tabView = null; // Use the "tag" for the tab spec to determine which tab is selected if (tag.equals("home")) { tabView = getTabWidget().getChildAt(0); } else if (tag.equals("users")) { tabView = getTabWidget().getChildAt(1); } tabView.findViewById(R.id.tabSelectedDivider).setVisibility(View.VISIBLE); } }); } private void clearTabStyles() { for (int i = 0; i &lt; getTabWidget().getChildCount(); i++) { tab = getTabWidget().getChildAt(i); tab.findViewById(R.id.tabSelectedDivider).setVisibility(View.GONE); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload