I am programatically showing the soft keyboard when a layout is loaded on a button click.
I am showing the softkeyboard only when the textfield has focus. It works fine. But when I call the same method at another place in the code(not a button click) then the soft keyboard does not show up. Below is my code. Please point out where I went wrong.
public void showNewView() {
setContentView(R.layout.activity_main);
this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
isRegisterScreen = true;
final EditText text1 = (EditText) findViewById(R.id.label1);
final EditText text2 = (EditText) findViewById(R.id.label2);
final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
text1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
inputManager.showSoftInput(labelText, InputMethodManager.SHOW_IMPLICIT);
}else{
inputManager.hideSoftInputFromWindow(text1.getWindowToken(), 0);
}
}
});
text2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
inputManager.showSoftInput(text2, InputMethodManager.SHOW_IMPLICIT);
}else{
inputManager.hideSoftInputFromWindow(phoneText.getWindowToken(), 0);
}
}
});
text1.requestFocus();
}
Related
I have a button to open the browser to fullscreen mode. This is the code:
private void ResizeButton_OnClick (UberButton obj)
{
if (!Screen.fullScreen)
Screen.fullScreen = true;
else
Screen.fullScreen = false;
}
How can I implement automatic button pressing when the screen orientation changes
private void Update()
{
if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)
{
// ...
}
}
I want my dialog to stick to the start but it always comes in the center.
i will give you example==>
Following is the code -->Onclick image -->Dialog Appears==>
Dialog dialog; //your dialog declaration
//
//
//
oncreate(){
imageView = (ImageView) findViewById(R.id.customProfileGridImg);
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity);
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.START |Gravity.TOP; //change direction as per your requirement
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.show();
}
});
}
Just like new google guidelines I want to hide actionbar on listview scroll.
I have succeeded in implementing the same but if I scroll slowly the actionbar flickers. How can provide smooth animation on its show and hide.
This is my code
lv.setOnScrollListener(new OnScrollListener() {
private int mLast;
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
if (mLast < firstVisibleItem) {
if (getSupportActionBar().isShowing()) {
getSupportActionBar().hide();
}
}
if (mLast > firstVisibleItem) {
if (!getSupportActionBar().isShowing()) {
getSupportActionBar().show();
}
}
mLast = firstVisibleItem;
}
});
I have even tried putting these value for listview
android:clipToPadding="false"
But it just doesn't seem to work.
I want to create Single and Double click on Button in Android...
Thanks for help in Advance.
I have already tried using button.setOnClickListener() for single click on button but i couldn't find double click on button
Try this code : (btn is the button you want to check for single and double click)
int i = 0;
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
i++;
Handler handler = new Handler();
Runnable r = new Runnable() {
#Override
public void run() {
i = 0;
}
};
if (i == 1) {
//Single click
handler.postDelayed(r, 250);
} else if (i == 2) {
//Double click
i = 0;
ShowDailog();
}
}
});
The docs say the button should fire for clicks, keypress, and touch. It doesn't seem to work.
Some code to play with.
public class FireButtonTest extends Application {
#Override
public void start(Stage primaryStage) {
TextArea ta = new TextArea();
Button btn1 = new Button();
btn1.setText("btn1");
btn1.setOnAction((ActionEvent event) -> {
ta.setText(ta.getText()+"btn1 fired \n");
});
Button btn2 = new Button();
btn2.setText("btn2");
btn2.setOnAction((ActionEvent event) -> {
ta.setText(ta.getText()+"btn2 fired \n");
});
btn2.setOnKeyReleased((KeyEvent ke) -> {
if (ke.getCode() == KeyCode.ENTER) {
ta.setText(ta.getText()+"btn2 key event -> ");
btn2.fire();
}
});
//?? can't test this
btn2.setOnTouchReleased((TouchEvent te) -> {
if (te.getTouchCount() == 1){
ta.setText(ta.getText()+"btn2 touch event -> ");
btn2.fire();
}
});
VBox root = new VBox(5);
root.getChildren().addAll(btn1, btn2, ta);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Button Test");
primaryStage.setScene(scene);
primaryStage.show();
}
}
Why can't I just press enter when the button is focused?
Doh! I guess you have to use the space bar. Here's the source.
<!-- language: java -->
protected static final List<KeyBinding> BUTTON_BINDINGS = new ArrayList<KeyBinding>();
static {
BUTTON_BINDINGS.add(new KeyBinding(SPACE, KEY_PRESSED, PRESS_ACTION));
BUTTON_BINDINGS.add(new KeyBinding(SPACE, KEY_RELEASED, RELEASE_ACTION));
}