BaseAdapter导致EditText不起作用

时间:2016-09-09 09:30:31

标签: android android-edittext baseadapter android-gallery

每当我使用基础适配器将视图添加到图库时,它会导致视图中的EditText不允许文本输入,它会聚焦并且键盘会出现但是当我输入文本时它不会显示。出现了。 EditText类型为numberDecimal

我尝试将MainActivity的内容视图设置为ap_overview_addEditText正常工作。

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.mwapps.baseadaptertest.MainActivity">

    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.6"
        android:padding="20dp" />

</RelativeLayout>

ap_overview_add.xml

<?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"
    android:id="@+id/ap_overview_add_LL"
    android:gravity="center">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:id="@+id/ap_et_add"
            android:inputType="numberDecimal"
            android:padding="10dp"
            android:backgroundTint="@color/abc_secondary_text_material_light"
            android:imeOptions="actionSend"
            android:lines="1"
            android:maxLines="1"
            android:singleLine="true"
            android:layout_weight=".75"
            android:clickable="true"
            android:text="300"
            android:focusable="true"
            android:focusableInTouchMode="true" />

</LinearLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    Gallery gallery;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        gallery = (Gallery) findViewById(R.id.gallery1);
        gallery.setAdapter(new GalleryImageAdapter(this));
    }
}

GalleryImageAdapter.java

public class GalleryImageAdapter extends BaseAdapter {
        Context mContext;
        LayoutInflater inflater;

        public GalleryImageAdapter(Context context)
        {
            mContext = context;
        }

        public int getCount() {
            return 1;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        // Override this method according to your need
        public View getView(int index, View view, ViewGroup viewGroup)
        {
            // TODO Auto-generated method stub
            inflater = LayoutInflater.from(mContext);
            View tab;
            tab = inflater.inflate(R.layout.ap_overview_add, viewGroup, false);

            return tab;
        }
}

我已经查看了类似的其他问题但没有任何效果,包括尝试更改softinput模式,导致文本无法输入的原因是什么?

编辑:如果inputType更改为文本,则允许输入

编辑2:如果输入类型设置为numberDecimal,则无法输入数字,但可以使用逗号之类的内容,因此看起来它不接受数字

1 个答案:

答案 0 :(得分:1)

您可以按照developer.android.com/reference/android/widget/Gallery.html中的建议使用ViewPager而不是图库 使它工作