2012-03-17 17 views
15

इस विषय को छूने वाली कुछ पोस्ट हैं। मैंने सोचा कि मुझे यह स्पष्ट प्रश्न पूछना चाहिए कि इसे स्पष्ट करने की उम्मीद है।बटन को फ़ोकस कैसे प्राप्त किया जा सकता है?

मैं एक बटन पर ध्यान केंद्रित करने में असमर्थ हूं। मुझे पता है कि शायद मुझे कुछ मौलिक याद आती है।

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:focusable="true" /> 

</LinearLayout> 

निम्नलिखित) OnCreate (में सरल कोड है:: यहाँ सरल लेआउट है

 Button button = (Button)findViewById(R.id.button1); 
     button.setFocusable(true); 
     button.requestFocus(); 
     button.setText("Debug"); //Just to show the code here has been executed 

यह बस काम नहीं करता है (अर्थात बटन ध्यान नहीं प्राप्त करता है)।

मेरी त्रुटि या गलतफहमी के किसी भी सुधार की सराहना की जाएगी।

अपने कोड

उत्तर

34

अद्यतन:

 Button button = (Button)findViewById(R.id.button1); 
     button.setFocusable(true); 
     button.setFocusableInTouchMode(true);///add this line 
     button.requestFocus(); 
     button.setText("Debug"); 
+1

बटन फोकस अन्यथा भी होगा, लेकिन आप यह नहीं देख पाते। दृश्य फोकस केवल [टचमोड] में है (http://android-developers.blogspot.de/2008/12/touch-mode.html) – zapl

+0

त्वरित प्रतिक्रिया और स्पष्टीकरण के लिए सभी को धन्यवाद। स्पष्ट रूप से मुझे समझ में नहीं आया कि विशेष संदर्भ में "फोकस" का क्या अर्थ है। अब मुझे आश्चर्य है कि एक बटन जो दिखाए बिना फोकस प्राप्त कर रहा है। – Hong

+1

कहें कि आपके पास अपने डिवाइस से जुड़ा एक कीबोर्ड है (जैसे एम्यूलेटर है) या आपके पास डी-पैड वाला डिवाइस है और आपने एंटर/क्लिक dpad दबाया है। जो भी फोकस है उसे अभी कहा जाता है। यदि आप बस अपनी उंगलियों के साथ ऐप का उपयोग करते हैं तो आप आमतौर पर फोकस को अनदेखा कर सकते हैं। – zapl

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