为什么机器人TabHost偷焦点从一个TextView?机器人、焦点、TabHost、TextView

2023-09-05 08:16:56 作者:草莓味的风

我用下面的布局有一个应用程序:

当应用程序启动,重点是第一个TextView的,但如果你尝试在它输入任何字母,焦点直接进入制表符。看来,我不是唯一的一个这个问题的战斗,也许这是关系到以下内容:

http://groups.google.com/group/android-developers/browse_thread/thread/435791bbd6c550a/8022183887f38f4f?lnk=gst&q=tabs+focus#8022183887f38f4f

不管怎样,有你的,为什么出现这种情况的任何想法?当然,任何解决方法是AP preciated。

我在下方的code,以避免超载的问题:

中的XML:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    <的LinearLayout
          机器人:填充=5像素
          机器人:方向=垂直
          机器人:ID =@ + ID / task_edit_panel
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =FILL_PARENT
           机器人:layout_weight =50>
        <的LinearLayout机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>
    < TextView的Andr​​oid的:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=@字符串/标题
    机器人:TEXTSTYLE =黑体/>
    < EditText上机器人:ID =@ + ID /标题
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT/>
    < / LinearLayout中>
    < TabHost机器人:ID =@ + ID / edit_item_tab_host
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT>
            < TabWidget机器人:layout_width =FILL_PARENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:ID =@机器人:ID /标签/>
    <的FrameLayout
              机器人:ID =@机器人:ID / tabcontent
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =FILL_PARENT
              机器人:paddingTop =65px> <! - 你需要的,如果你不想要的标签内容溢出 - >
              <的LinearLayout
                   机器人:ID =@ + ID / edit_item_date_tab
                   机器人:方向=垂直
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =FILL_PARENT
                    机器人:填充=5px的>
    < TextView的Andr​​oid的:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=日期
    机器人:TEXTSTYLE =黑体/>
    < / LinearLayout中>
    <的LinearLayout
                   机器人:ID =@ + ID / edit_item_geocontext_tab
                   机器人:方向=垂直
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =FILL_PARENT
                    机器人:填充=5px的>
    < TextView的Andr​​oid的:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=代替
    机器人:TEXTSTYLE =黑体/>
    < / LinearLayout中>
    <的LinearLayout
                   机器人:ID =@ + ID / edit_item_text_tab
                   机器人:方向=垂直
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =FILL_PARENT
                     机器人:填充=5px的>
    < EditText上机器人:ID =@ + ID /详细信息
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:滚动条=垂直/>
    < / LinearLayout中>
    < /的FrameLayout>
    < / TabHost>
    < / LinearLayout中>
    <! - 底部潘内尔与添加项目按钮 - >
    <的LinearLayout
          机器人:填充=5像素
          机器人:方向=横向
          机器人:layout_weight =1
          机器人:ID =@ + ID / task_edit_panel
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =WRAP_CONTENT
          机器人:后台=#E7E7E7>
          <! - 让我们的高度设置为FILL_PARENT直到我们找到的布局更好的办法 - >
          <按钮机器人:ID =@ + ID / item_edit_ok_button
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =底
                机器人:文本=@字符串/ OK
                风格=机器人:ATTR / buttonStyleSmall
                机器人:layout_weight =1/>
           <按钮机器人:ID =@ + ID / item_edit_cancel_button
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =底
                机器人:文本=@字符串/取消
                风格=机器人:ATTR / buttonStyleSmall
                机器人:layout_weight =1/>
    < / LinearLayout中>
< / LinearLayout中>
 

和Java code:

  TabHost tab_host =(TabHost)findViewById(R.id.edit_item_tab_host);
     //使用XML视图从tabhost添加标签之前,不要忘了这个设置,否则你会得到一个空指针异常
    tab_host.setup();

    则tabspec TS1 = tab_host.newTabSpec(TAB_DATE);
    ts1.setIndicator(的getString(R.string.when),getResources()getDrawable(R.drawable.ic_dialog_time));
    ts1.setContent(R.id.edit_item_date_tab);
    tab_host.addTab(TS1);

    则tabspec TS2 = tab_host.newTabSpec(TAB_GEO);
    ts2.setIndicator(的getString(R.string.where),getResources()getDrawable(R.drawable.ic_dialog_map));
    ts2.setContent(R.id.edit_item_geocontext_tab);
    tab_host.addTab(TS2);

    则tabspec TS3 = tab_host.newTabSpec(TAB_TEXT);
    ts3.setIndicator(的getString(R.string.what),getResources()getDrawable(R.drawable.ic_menu_edit));
    ts3.setContent(R.id.edit_item_text_tab);
    tab_host.addTab(TS3);

    tab_host.setCurrentTab(0);
 
商业服务机器人助力业务增值 temi成2020市场新焦点

解决方案

嗯,definitly一个错误:http://$c$c.google.com/p/android/issues/detail?id=2516.

希望这将是固定在下一版本,因为这是对于复杂的应用程序真正是烦人的问题了先进的布局。

I have an application using the following layout :

When the app start, the focus is on the first TextView, but if you try to type any letter in it, the focus goes directly to the tabs. It seems that I am not the only one fighting with this issue, and maybe this is related to the following :

http://groups.google.com/group/android-developers/browse_thread/thread/435791bbd6c550a/8022183887f38f4f?lnk=gst&q=tabs+focus#8022183887f38f4f

Anyway, have you any idea of why that happens ? And of course, any workaround would be appreciated.

I post the code below to avoid overloading the question :

The XML :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout 
          android:padding="5px"
          android:orientation="vertical" 
          android:id="@+id/task_edit_panel"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
           android:layout_weight="50" >
        <LinearLayout android:orientation="vertical"
    		android:layout_width="fill_parent"
    		android:layout_height="wrap_content">
    		<TextView android:layout_width="wrap_content"
    			android:layout_height="wrap_content" 
    			android:text="@string/title" 
    		    android:textStyle="bold" />
    		<EditText android:id="@+id/title" 
    		  android:layout_width="fill_parent"
    			android:layout_height="fill_parent" />
    	</LinearLayout>
    	<TabHost android:id="@+id/edit_item_tab_host"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"> 
            <TabWidget android:layout_width="fill_parent"
                        android:layout_height="wrap_content" 
                        android:id="@android:id/tabs" /> 
    		<FrameLayout
              android:id="@android:id/tabcontent"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:paddingTop="65px"> <!--  you need that if you don't want the tab content to overflow --> 
              <LinearLayout
                   android:id="@+id/edit_item_date_tab"
                   android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:padding="5px" > 
    				<TextView android:layout_width="wrap_content"
    						android:layout_height="wrap_content" 
    						android:text="date" 
    						 android:textStyle="bold" />
    			</LinearLayout>
    		    <LinearLayout
                   android:id="@+id/edit_item_geocontext_tab"
                   android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:padding="5px" > 
    			<TextView android:layout_width="wrap_content"
    						android:layout_height="wrap_content" 
    						android:text="lieu" 
    						 android:textStyle="bold" />
    			</LinearLayout>
    	        <LinearLayout
                   android:id="@+id/edit_item_text_tab"
                   android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                     android:padding="5px"> 
    			<EditText android:id="@+id/details" 
    				    android:layout_width="fill_parent"
    					android:layout_height="fill_parent"
    					android:scrollbars="vertical" />
    			</LinearLayout>
    		</FrameLayout>
    	</TabHost>
    </LinearLayout>
    <!-- Bottom pannel with "add item" button -->
    <LinearLayout 
          android:padding="5px"
          android:orientation="horizontal" 
          android:layout_weight="1"
          android:id="@+id/task_edit_panel"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#E7E7E7" >
          <!--  Let the height set to fill_parent until we find a better way for the layout  -->
          <Button android:id="@+id/item_edit_ok_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:text="@string/ok"
                style="?android:attr/buttonStyleSmall"
                android:layout_weight="1" />
           <Button android:id="@+id/item_edit_cancel_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:text="@string/cancel"
                style="?android:attr/buttonStyleSmall"
                android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>

And the Java code :

    TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
     // don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
    tab_host.setup(); 

    TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
    ts1.setIndicator(getString(R.string.when), getResources().getDrawable(R.drawable.ic_dialog_time));
    ts1.setContent(R.id.edit_item_date_tab);
    tab_host.addTab(ts1);

    TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
    ts2.setIndicator(getString(R.string.where),  getResources().getDrawable(R.drawable.ic_dialog_map));
    ts2.setContent(R.id.edit_item_geocontext_tab);
    tab_host.addTab(ts2);

    TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
    ts3.setIndicator(getString(R.string.what),  getResources().getDrawable(R.drawable.ic_menu_edit));
    ts3.setContent(R.id.edit_item_text_tab);
    tab_host.addTab(ts3);

    tab_host.setCurrentTab(0);

解决方案

Well, definitly a bug : http://code.google.com/p/android/issues/detail?id=2516.

Hope it will be fixed in the next release because this is a really anoying issues for complex apps with an advanced layout.

 
精彩推荐
图片推荐