Reputation: 57
I have created a project in which, I have a class that extends fragments, in which the frame layout consist two edit text. Problem here is whenever I click/touch on any edit text, the soft input keyboard popups which I don't want to popups. I tried the following method to disable the soft input keyboard.
In androidmanifest.xml
file, I have also used the property android:windowSoftInputMode="stateHidden"
public class Convert extends Fragment{
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
final ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.converter_data_layout, container, false);
screen_v1 = (EditText) viewGroup.findViewById(R.id.data_value1);
screen_v2 = (EditText) viewGroup.findViewById(R.id.data_value2);
screen_v1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
hideKeyboard(getContext());
}
});
screen_v2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
hideKeyboard(getContext());
}
});
return viewGroup;
}
public void hideKeyboard(Context context){
InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
View view = ((Activity)context).getCurrentFocus();
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
My xml file code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="rahuldadoriya.mathsolver.convert.Convert"
android:id="@+id/frame_data">
<EditText
android:maxLength="15"
android:id="@+id/data_value1"
style="@style/EdittextStyle"
android:layout_weight="2.8"
android:gravity="right"
android:paddingRight="15dp"
android:paddingTop="25dp"
android:inputType="numberDecimal"
android:clickable="true"/>
<EditText
android:maxLength="15"
android:id="@+id/data_value2"
style="@style/EdittextStyle"
android:layout_weight="2.8"
android:gravity="right"
android:paddingRight="15dp"
android:paddingTop="25dp"
android:inputType="numberDecimal"
android:clickable="true"/>
</FrameLayout>
Thanks in advance.
Upvotes: 1
Views: 98
Reputation: 57
thanks for your help, I have solved my problem but not fully satisfied with the solution, because what i have used for not popping up the soft input keyboard is setting setInputType(0)
for both the edittext, i.e.
screen_v1.setInputType(0);
similarly for the other edittext but the issues here is after using the above method on both the edittext, cursor is not visible on either of the edittext. So if any one have any reason why it is happening so please help me.
Thanks
Upvotes: 1