按下返回键时,listview内的Edittext失去焦点

时间:2014-11-18 05:56:09

标签: android listview android-edittext xamarin focus

我有一个listview,里面有几个编辑文本。最初我遇到了第一次选择时编辑文本无法获得焦点的问题,我能够在this link

的帮助下解决问题

我有一个多行的edittext,就像这样定义

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <EditText
        android:inputType="textMultiLine"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:id="@+id/multiLineText" />
</LinearLayout>

在此编辑文本中,只要按下返回键,它就会失去焦点。查看堆栈跟踪指向运行时异常

11-18 11:13:37.675 W/Binder  (25836): Caught a RuntimeException from the binder stub implementation.
11-18 11:13:37.675 W/Binder  (25836): java.lang.NullPointerException
11-18 11:13:37.675 W/Binder  (25836):   at android.view.textservice.SpellCheckerSession$SpellCheckerSessionListenerImpl.onGetSentenceSuggestions(SpellCheckerSession.java:430)
11-18 11:13:37.675 W/Binder  (25836):   at com.android.internal.textservice.ISpellCheckerSessionListener$Stub.onTransact(ISpellCheckerSessionListener.java:61)
11-18 11:13:37.675 W/Binder  (25836):   at android.os.Binder.execTransact(Binder.java:404)
11-18 11:13:37.675 W/Binder  (25836):   at dalvik.system.NativeStart.run(Native Method)

我对导致此异常的原因一无所知。任何帮助将不胜感激。

修改:附加代码

主ListView布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/newListView"
        android:descendantFocusability="beforeDescendants" />
</LinearLayout>

主要活动

[Activity(Label = "New", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, WindowSoftInputMode=SoftInput.AdjustPan)]
    public class NewActivity : Activity
    {
        ListView newListView;
        NewListAdapter source;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.NewView);
            newListView = FindViewById<ListView>(Resource.Id.newListView);
            var items = GetItems(); // returns list of custom objects
            source = new NewListAdapter(this, items);
            newListView.Adapter = source;
        }
}

自定义适配器 - GetView

public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var item = this[position];
            View view = convertView;
            if (view == null)
            {

                NewItemType type = (NewItemType)GetItemViewType(position);
                switch (type)
                { 
                    //other items
                    case (NewItemType.Notes):
                     view = context.LayoutInflater.Inflate(Resource.Layout.text_input_list_item, null); //layout for the troublesome edit text
                     break;
                }
            }               

            return view;
        }

0 个答案:

没有答案