Daha sağlam bir çözüm öneririm:
Kullanıcıya giriş türünü seçme olanağı sunun:
GEREKLİ DÜZELTMELER
- giriş seçimi düğmelerinin daha iyi gösterilmesi / gizlenmesi
- muhtemelen giriş türü harf olduğunda önerileri kaldırın
İşte etkinlik:
package mobi.sherif.numberstexttextview;
import android.os.Bundle;
import android.app.Activity;
import android.text.InputType;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText mEdit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEdit = (EditText) findViewById(R.id.input);
mEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean focused) {
findViewById(R.id.llmenu).setVisibility(focused?View.VISIBLE:View.GONE);
}
});
}
public void onNumbers(View v) {
mEdit.setInputType(InputType.TYPE_CLASS_NUMBER);
}
public void onLetters(View v) {
mEdit.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
İşte etkinliğin xml'si: activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignWithParentIfMissing="true"
android:layout_above="@+id/llmenu" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" >
<requestFocus />
</EditText>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/llmenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#000000"
android:padding="0dp" >
<Button
android:id="@+id/buttonnumbers"
android:layout_width="0dp"
android:onClick="onNumbers"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Numbers" />
<Button
android:id="@+id/buttonletters"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="onLetters"
android:text="Letters" />
</LinearLayout>
</RelativeLayout>