Java 选项卡和文件显示

Java 选项卡和文件显示,java,android,Java,Android,我想知道是否有一种简单的方法可以让我的标签显示布局文件夹中的文件。我曾考虑过使用webview来显示,但有没有更好的方法,只是好奇而已。下面是我的代码 import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class TabContentActivity extends Activity { @Override

我想知道是否有一种简单的方法可以让我的标签显示布局文件夹中的文件。我曾考虑过使用webview来显示,但有没有更好的方法,只是好奇而已。下面是我的代码

   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

<!-- language: xml -->    

    <?xml version="1.0" encoding="utf-8"?>
    <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" >

        <LinearLayout
            android:id="@+id/tabcontainer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="48dp"
                android:background="#000"
                android:gravity="center_horizontal" >
            </TabWidget>

            <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" >
            </FrameLayout>
        </LinearLayout>

    </TabHost>

    <?xml version="1.0" encoding="utf-8"?>
    <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" >

        <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" />

        <TextView
            android:id="@+id/tabSelectedDivider"
            android:layout_width="fill_parent"
            android:layout_height="5dp"
            android:layout_alignParentBottom="true"
            android:background="#3366CC"
            android:visibility="gone" />

        <TextView
            android:id="@+id/tabDivider"
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:layout_alignParentBottom="true"
            android:background="#3366CC" />

        <TextView
            android:id="@+id/tabSplitter"
            android:layout_width="1px"
            android:layout_height="23dp"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:background="#333" />

    </RelativeLayout>



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 => 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 < getTabWidget().getChildCount(); i++) {
            tab = getTabWidget().getChildAt(i);
            tab.findViewById(R.id.tabSelectedDivider).setVisibility(View.GONE);
        }
    }
}
导入android.app.Activity;
导入android.os.Bundle;
导入android.widget.TextView;
公共类TabContentActivity扩展了活动{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView TextView=新的TextView(此);
setText(getIntent().getStringExtra(“内容”));
setContentView(文本视图);
}
}
布局
导入android.app.TabActivity;
导入android.content.Context;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.widget.LinearLayout;
导入android.widget.LinearLayout.LayoutParams;
导入android.widget.TabHost;
导入android.widget.TabHost.OnTabChangeListener;
导入android.widget.TextView;
公共类TabTutorialActivity扩展了TabActivity{
//将1.0除以所需制表符的#
//在这种情况下:1.0/2=>0.5
private static final LayoutParams params=新的LinearLayout.LayoutParams(
LayoutParams.FILL_父级,LayoutParams.WRAP_内容,0.5f);
私有静态TabHost TabHost;
私有静态TabHost.TabSpec;
私人静态意图;
私人静电充气机;
“私人视图”选项卡;
私有文本视图标签;
私有文本视图分割器;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取充气器,以便开始为选项卡创建自定义视图
充气器=(LayoutInflater)getSystemService(Context.LAYOUT\u充气器\u SERVICE);
//获取选项卡管理器
tabHost=getTabHost();
//这将转换我们创建的自定义选项卡视图,并将其注入到选项卡小部件中
tab=充气机。充气(R.layout.tab,getTabWidget(),false);
//主要用于设置标签上的重量,使每个标签宽度相等
tab.setLayoutParams(参数);
//向选项卡添加一些文本
label=(TextView)tab.findViewById(R.id.tabLabel);
label.setText(“报告计数器”);
//在所选选项卡下显示粗线(有多种显示方式
//选择了哪个选项卡,我选择了这个)
分隔符=(TextView)tab.findViewById(R.id.tabSelectedDivider);
分隔符.setVisibility(View.VISIBLE);
//其生成的内容将添加到选项卡内容区域的意图
意图=新意图(TabTutorialActivity.this、TabContentActivity.class);
//只是一些用于选项卡内容活动的数据(仅用于演示更改的内容)
意图。putExtra(“内容”、“家庭内容”);
//完成tabs规范
spec=tabHost.newTabSpec(“主”).setIndicator(tab).setContent(intent);
//将选项卡添加到选项卡管理器
tabHost.addTab(spec);
//添加另一个选项卡
tab=充气机。充气(R.layout.tab,getTabWidget(),false);
tab.setLayoutParams(参数);
label=(TextView)tab.findViewById(R.id.tabLabel);
label.setText(“BMI”);
意图=新意图(TabTutorialActivity.this、TabContentActivity.class);
intent.putExtra(“内容”、“用户内容”);
spec=tabHost.newTabSpec(“用户”).setIndicator(tab).setContent(intent);
tabHost.addTab(spec);
//侦听器来检测选项卡何时更改。我添加此项只是为了显示
//如何更改UI以强调所选选项卡
tabHost.setOnTabChangedListener(新的ontabchangedListener(){
@凌驾
已更改的公用void onTabChanged(字符串标记){
//重置一些样式
clearTabStyles();
视图选项卡视图=空;
//使用选项卡规范的“标记”来确定选择哪个选项卡
如果(标记等于(“主”)){
tabView=getTabWidget().getChildAt(0);
}
else if(tag.equals(“用户”)){
tabView=getTabWidget().getChildAt(1);
}
tabView.findViewById(R.id.tabSelectedDivider).setVisibility(View.VISIBLE);
}       
});
}
私有void clearTabStyles(){
对于(int i=0;i
您是从哪里发送内容视图意图的???@Brijesh Thakur。。。我将intent文件添加到bottom,如果它是纯文本,您可以使用Textview。Webview只能用于显示HTML内容