TextView和Button未出现在Android TabHost中 [英] TextView and Button not appeared In Android TabHost

查看:64
本文介绍了TextView和Button未出现在Android TabHost中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Frieds我正在学习Android ..

我正在使用tabhost控件。

在这个TabHost中共有3个选项卡。

全部三个标签有用户名,密码文本视图和登录和取消按钮。

当我运行这个应用程序时,它只会显示在第一个标签点击。

点击后我点击在第二个选项卡上是Doctor,只显示一个textview。

如何解决这个问题..

我在这里提供XML文件和Java文件代码。 />
提前使用Thanx ..



activity_main.xml






Frieds I am learning Android..
I am using tabhost control.
In this TabHost there are total 3 tabs.
All three tabs having Username,Password Textview and Login and Cancel Button.
When I am running this app it will only show to in First Tab click.
After when i am clicking on Second Tab that is "Doctor",only one textview appear.
How to Solve this Problem..
I m giving XML file and Java file code here.
Thanx in advance..

activity_main.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:android1="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >

    <TabHost

        android1:id="@+id/tabhost"

        android1:layout_width="match_parent"

        android1:layout_height="match_parent"

        android1:layout_weight="1" >

        <LinearLayout

            android1:layout_width="match_parent"

            android1:layout_height="match_parent"

            android1:orientation="vertical" >

            <TabWidget

                android1:id="@android:id/tabs"

                android1:layout_width="match_parent"

                android1:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout

                android1:id="@android:id/tabcontent"

                android1:layout_width="match_parent"

                android1:layout_height="match_parent" >

                <LinearLayout

                    android1:id="@+id/tab1"

                    android1:layout_width="match_parent"

                    android1:layout_height="match_parent"

                    android1:orientation="vertical" >

                    <EditText

                        android1:id="@+id/tvUsername"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content"

                        android1:ems="10"

                        android1:hint="User Name"

                        android1:inputType="textPersonName" >

                        <requestFocus />
                    </EditText>

                    <EditText

                        android1:id="@+id/tvUpswd"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content"

                        android1:ems="10"

                        android1:hint="Password"

                        android1:inputType="textPassword" />

                    <TableRow

                        android1:id="@+id/tableRow1"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content" >

                        <Button

                            android1:id="@+id/bUlogin"

                            android1:layout_width="wrap_content"

                            android1:layout_height="wrap_content"

                            android1:text="Login" />


                        <Button

                            android1:id="@+id/bUcancel"

                            android1:layout_width="wrap_content"

                            android1:layout_height="wrap_content"

                            android1:text="Cancel" />

                    </TableRow>

                    
                </LinearLayout>

                <LinearLayout

                    android1:id="@+id/tab2"

                    android1:layout_width="match_parent"

                    android1:layout_height="match_parent" >
                    
                                        <EditText

                        android1:id="@+id/Dname"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content"

                        android1:ems="10"

                        android1:hint="Doctor Name"

                        android1:inputType="textPersonName" >

                        <requestFocus />
                    </EditText>

                    <EditText

                        android1:id="@+id/tvDpswd"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content"

                        android1:ems="10"

                        android1:hint="Doctor Password"

                        android1:inputType="textPassword" />

                    <TableRow

                        android1:id="@+id/tableRow2"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content" >

                        <Button

                            android1:id="@+id/bDlogin"

                            android1:layout_width="wrap_content"

                            android1:layout_height="wrap_content"

                            android1:text="Login" />


                        <Button

                            android1:id="@+id/bDcancel"

                            android1:layout_width="wrap_content"

                            android1:layout_height="wrap_content"

                            android1:text="Cancel" />

                    </TableRow>
                    
                    
                </LinearLayout>

                <LinearLayout

                    android1:id="@+id/tab3"

                    android1:layout_width="match_parent"

                    android1:layout_height="match_parent" >
                    
                                        <EditText

                        android1:id="@+id/tvUsername"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content"

                        android1:ems="10"

                        android1:hint="Clinic User Name"

                        android1:inputType="textPersonName" >

                        <requestFocus />
                    </EditText>

                    <EditText

                        android1:id="@+id/tvDpswd"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content"

                        android1:ems="10"

                        android1:hint="Password"

                        android1:inputType="textPassword" />

                    <TableRow

                        android1:id="@+id/tableRow3"

                        android1:layout_width="match_parent"

                        android1:layout_height="wrap_content" >

                        <Button

                            android1:id="@+id/bClogin"

                            android1:layout_width="wrap_content"

                            android1:layout_height="wrap_content"

                            android1:text="Login" />
                        <Button

                            android1:id="@+id/bCcancel"

                            android1:layout_width="wrap_content"

                            android1:layout_height="wrap_content"

                            android1:text="Cancel" />

                    </TableRow>
                    
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</LinearLayout>

推荐答案

Plz Reply...Its an Urgent..plz



And Its Java File is this.



MainActivity.java

Plz Reply...Its an Urgent..plz

And Its Java File is this.

MainActivity.java
package com.mca.doctoroid;

import java.io.Console;

import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.database.sqlite.SQLiteDatabase;

public class MainActivity extends Activity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		 TabHost th=(TabHost)findViewById(R.id.tabhost);
		 th.setup();
		 TabSpec specs1=th.newTabSpec("users");
		 specs1.setIndicator("Users");
		 specs1.setContent(R.id.tab1);
		 
		 TabSpec specs2=th.newTabSpec("doctors");
		 specs2.setIndicator("Doctors");
		 specs2.setContent(R.id.tab2);
		 		 
		 TabSpec specs3=th.newTabSpec("clinics");
		 specs3.setContent(R.id.tab3);
		 specs3.setIndicator("Clinics");
		 th.addTab(specs1);
		 th.addTab(specs2);
		 th.addTab(specs3);
	    }		
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}


这篇关于TextView和Button未出现在Android TabHost中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆