Whenever I use a base adapter to add a view to a gallery it causes the EditText
from within the view to not allow text input, it focuses and the keyboard appears but when I enter text it doesn't appear. The EditText
type is numberDecimal
.
I have tried setting the content view of MainActivity
to ap_overview_add
and the EditText
works fine.
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;
}
}
I've looked at other questions similar and nothing has worked, including trying to change the softinput
mode, what is causing the text to not be entered?
Edit: If the inputType is changed to text it allows input
Edit 2: If the inputtype is set to numberDecimal, numbers cannot be entered but things like commas can be, so it looks like it's not accepting numbers
You can use ViewPager instead of Gallery as suggested in developer.android.com/reference/android/widget/Gallery.html to make it work