2009-04-24 14 views
5

मैं निम्नलिखित लेआउट का उपयोग कर एक आवेदन है:Android TabHost टेक्स्ट व्यू से फ़ोकस क्यों चुरा रहा है?

alt text http://img15.imageshack.us/img15/238/screenshot003xbo.png

एप्लिकेशन शुरू, ध्यान पहले TextView पर है, लेकिन अगर आप इसे किसी भी अक्षर को टाइप करने का प्रयास करें, ध्यान केंद्रित करने के सीधे चला जाता है टैब। ऐसा लगता है कि मैं केवल एक fighting with this issue नहीं कर रहा हूँ, और शायद यह निम्नलिखित से संबंधित है:

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

वैसे भी, आप क्यों ऐसा होता है के किसी भी विचार है? और निश्चित रूप से, किसी भी कामकाज की सराहना की जाएगी।


मैं नीचे दिए गए कोड पोस्ट सवाल ओवरलोडिंग से बचने के लिए:

एक्सएमएल:

<?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> 

और जावा कोड:

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); 

उत्तर

6

ठीक है, निश्चित रूप से एक बग: http://code.google.com/p/android/issues/detail?id=2516

आशा है कि इसे अगली रिलीज में ठीक किया जाएगा क्योंकि यह एक उन्नत लेआउट के साथ जटिल ऐप्स के लिए वास्तव में एक कठिन समस्या है।

0

यदि यह संबंधित नहीं है उस अन्य बग को आपने इंगित किया (और ऐसा लगता है कि यह शायद है) और यदि आप इसे G1s पर अनुभव कर रहे हैं (और नहीं एम्यूलेटर) मुझे संदेह है कि आपकी समस्या यह है कि ध्यान केंद्रित करने के बाद या तो अभिविन्यास परिवर्तन (जब आप कीबोर्ड को फोल्ड करते हैं और लैंडस्केप मोड में जाते हैं) से पहले जमे हुए नहीं होते हैं या दृश्य को फिर से बनाया जाता है। आप गतिविधि के पर SaveInstanceState() और ऑनस्टोर इंस्टेंसस्टेट() फ़ोकस को सहेजने/पुनर्स्थापित करने के तरीकों को ओवरराइड करने का प्रयास कर सकते हैं।

6

मुझे हनीकॉम्ब के साथ एक ही तरह का मुद्दा सामना करना पड़ रहा था लेकिन एक बहुत ही सरल समाधान मिला। इसलिए मैंने सोचा कि किसी के लिए मेरा अनुभव साझा करना सहायक हो सकता है। प्रत्येक बार जब एक टैब क्लिक किया जाता है, तो फोकस संपादन टेक्स्ट पर होता है और आप वास्तव में हार्ड कीबोर्ड के साथ टाइप कर सकते हैं लेकिन सॉफ्ट कीबोर्ड कभी पॉप अप नहीं होता है।

input1.requestFocusFromTouch(); 
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(input1, InputMethodManager.SHOW_FORCED); 

समाधान:: मुख्य वर्ग जहां टैब्स संभाल रहे हैं में, बस जावा कोड नीचे लिखें:

myTabHost.setOnTabChangedListener(new OnTabChangeListener(){  
    public void onTabChanged(String tabID) {  
     myTabHost.clearFocus(); 
    } 
}); 
0

इस उदाहरण बताएंगे कि कैसे ठीक करने के लिए यहां तक ​​कि नीचे दिए गए कोड के साथ, यह इस मुद्दे को हल नहीं किया था इस मुद्दे:

userNameEditText.setOnTouchListener(new OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       userNameEditText.requestFocusFromTouch(); 
       return false; 
      } 
     }); 
0
सभी चश्मा जोड़ने के बाद

जावा फ़ाइल में अपने edittext को requestFocus विधि जोड़ने

+1

आपका मतलब है कि समाधान 'एडिटटेक्स्ट' से कक्षा प्राप्त करना है, 'अनुरोध फोकस' विधि को ओवरराइड करना है और यूआई बनाने के दौरान मानक 'एडिटटेक्स्ट' के बजाय इसका उपयोग करना है? –

संबंधित मुद्दे