2010-07-28 8 views
6

के साथ एक दृश्य शामिल है, मेरे पास एक सूची एडाप्टर है जिसमें इस मामले में एक आइटम है। वह आइटम उस दृश्य को उत्पन्न करता है जिसमें एक संपादन टेक्स्ट है।ListAdapter आइटम के लिए ओपन सॉफ्ट कीबोर्ड जिसमें स्ट्रिंग

जब दृश्य प्रदर्शित होता है तो मैं नरम कीबोर्ड खोलना चाहता हूं ताकि उपयोगकर्ता फ़ील्ड को संपादित कर सके।

मैं एडाप्टर के getView() फ़ंक्शन में कॉल करने की कोशिश:

View edittext = view.findViewById(R.id.EditText01); 
edittext.requestFocus(); 
mInputMgr.showSoftInput(edittext, InputMethodManager.SHOW_FORCED); 

जो कुछ भी करने को नहीं लगता है।

मैं भी करने की कोशिश की:

View edittext = view.findViewById(R.id.EditText01); 
edittext.requestFocus(); 
mInputMgr.toggleSoftInput(0, 0); 

कि कुछ रहस्यमय कारण एक पाश जिसमें softkeyboard खोला और repeatably बंद कर दिया जाता है के लिए तैयार करता है।

जब मैं अनुरोध को हटा देता हूं और प्रोग्राम में एडिटटेक्स्ट पर क्लिक स्पर्श करता है तो यह सॉफ्टकीबोर्ड को पॉप करता है लेकिन अनुरोध करता है कि अनुरोध फ़ोकस शो है सॉफ़्ट इनपुट काम नहीं कर रहा है।

मुझे क्या करना है? सूची तत्व की

एक्सएमएल:

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

    android:focusable="true" 
    android:background="@color/light_blue" 
    > 

<EditText android:id="@+id/EditText01" 
android:layout_height="wrap_content" 
android:text="" 
android:focusable="true" 
android:layout_width="fill_parent" android:inputType="textShortMessage"></EditText> 
</RelativeLayout> 

एक्सएमएल कि ListView शामिल हैं:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:layout_height="fill_parent" 
    > 
    <Button android:text="@+id/Button01" 
     android:id="@+id/Button01" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge"/> 
    <ListView android:id="@+id/ListView01" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Button01" 
     android:gravity="center_horizontal" 
     /> 
</RelativeLayout> 

लंबे getView समारोह: में एक्सएमएल में android:focusable="true" या setFocusable(true) स्थापित करने के लिए

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    if (convertView != null){ 
     return convertView; 
    } 

    if (mDialog!=null){ 
     final Choice thisChoice = mDialog.getChoice(
       position, 
       mContentRes); 
     Log.v(TAG, "DialogAdapter: "+ thisChoice.toString()); 

     View view = thisChoice.getView(
       mInflater, parent, mFillInput, mDialog); 
     View.OnClickListener listener = new View.OnClickListener() { 
      public void onClick(View v) { 
       if (thisChoice.choiceSingleClick(mDialog)){ 
        Log.i(TAG, 
          "Single Click selected Choice: " 
          + thisChoice.toString()); 
        Log.d(TAG, 
          "getNextInputId: " 
          + Integer.toString(
            thisChoice.getNextInputId())); 
        mFillInput.renderNext(thisChoice.getNextInputId()); 
       } 
       else{ 
        mFillInput.checkSelectedStatus(); 
       } 
      } 
     }; 
     view.setOnClickListener(listener); 

     View.OnLongClickListener longListener = new View.OnLongClickListener() { 
      public boolean onLongClick(View v) {    
       thisChoice.choiceLongClick(mDialog); 
       return false; 
      } 
     }; 
     view.setOnLongClickListener(longListener); 

     Log.d(TAG, "thisChoice: " + thisChoice); 
     Log.d(TAG, "selected: " + thisChoice.isSelected()); 
     if((position == 0 && mDialog.getSelectedCount() == 0) || 
       thisChoice.isSelected()){ 
      view.requestFocus(); 
     } 


     if (thisChoice.isEnterStringChoice() & position==0){ 
      Log.d(TAG, "Request Focus for StringChoice"); 
      View edittext = view.findViewById(R.id.EditText01); 
      edittext.requestFocus(); 
      //edittext.dispatchTouchEvent(null); 
      //FillInput.mInputMgr.showSoftInput(edittext, InputMethodManager.SHOW_FORCED); 
      //mFillInput.mInputMgr.toggleSoftInput(0, 0); 
     } 

     return view; 
    }   
    else{ 
     return null; 
    } 
} 
+0

आप कौन सा एसडीके संस्करण लक्षित कर रहे हैं? – iandisme

+0

इसके अलावा, आपके ListAdapter जेनरेट करने के लिए आप जिस एक्सएमएल और/या जावा का उपयोग कर रहे हैं वह उपयोगी होगा। – iandisme

+0

@iansideide: मैं इसे 1.5 में काम करना चाहता हूं लेकिन यदि आपके पास ऐसा कुछ है जो बाद में काम करता है तो मुझे भी दिलचस्पी होगी। – Christian

उत्तर

0

कोशिश आपके टेक्स्ट एडिट नियंत्रण पर जावा कोड

+1

यह व्यवहार को बदलता नहीं है। – Christian

1

क्या आपने पर EditText पर उपयोग करने का प्रयास किया था?

+1

ग्रहण \t \t \t \t edittext.dispatchTouchEvent (android.view.MotionEvent) को पहचान नहीं करता है; एक वैध टिप्पणी के रूप में। क्या आपका मतलब कुछ अलग था? – Christian

+0

@ क्रिस्टियन: आपको 'मोशनवेन्ट' बनाने की आवश्यकता है। http://developer.android.com/reference/android/view/MotionEvent देखें।एचटीएमएल – JRL

0

android:descendantFocusability="blocksDescendants" को अपने <RelativeLayout /> पर जोड़ने का प्रयास करें। इसे कभी-कभी बनाने के लिए आवश्यक होता है ताकि सूचियों में विजेट सही फोकस प्राप्त कर सकें।

+0

गलती, मेरा मानना ​​है कि मेरा मतलब है 'ब्लॉक डिस्केन्डेंट्स' के बजाय 'बाद में' डिस्कान्डेंट्स '। –

0

आप अपने EditText में <requestFocus /> जोड़ने की कोशिश कर सकते हैं:

<EditText android:id="@+id/EditText01" 
    android:layout_height="wrap_content" 
    android:text="" 
    android:focusable="true" 
    android:layout_width="fill_parent" android:inputType="textShortMessage"> 

    <requestFocus /> 
</EditText> 

या आप सही डिजाइन मोड में EditText पर क्लिक कर सकते हैं, Request Focus का चयन करें। उम्मीद है कि यह काम करेगा ...

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