当EditText失去焦点时我需要抓住,我已经搜索了其他问题,但我没有找到答案.
我用OnFocusChangeListener这样的
OnFocusChangeListener foco = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
}
};
Run Code Online (Sandbox Code Playgroud)
但是,它对我不起作用.
我们在一个布局中有17个api,DPAD控制和4个edittexts用于引脚输入.当用户试图打开锁定在应用程序中的某些东西时,他会面对片段,他应该输入4位数的针脚.当打开视图时,我们以编程方式将焦点设置为第一个针脚edittext并显示键盘.当用户输入第一个引脚数字时,我们将视图焦点设置为第二个引脚edittext,其中用户应输入第二个引脚值,依此类推.
问题: 在用户输入第一个引脚值后,键盘焦点(突出显示)消失,对于第二个引脚,用户应该再次从键盘开始导航.21 api相同的代码运行良好,键盘焦点(突出显示)保持在以前的值.如何在17 api之前保持键盘焦点(突出显示),同时将视图焦点设置在另一个视图上?
这是代码:
public class PasswordFragment extends BaseFragment {
private final ArrayList<Disposable> disposables = new ArrayList<>();
@BindViews({R.id.passFirst, R.id.passSecond, R.id.passThird, R.id.passFour})
EditText[] pinEdits;
@BindDrawable(R.drawable.border_light)
Drawable borderLight;
@BindDrawable(R.drawable.border_white)
Drawable borderWhite;
@Inject
PrefsRepo prefsRepo;
@Inject
ToastUtil toastUtil;
@BindView(R.id.passTitle)
TextView passTitle;
@BindString(R.string.insert_pin)
String defDialogMes;
private InputMethodManager inputMethodManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
App.getAppComponent().inject(this);
inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, …Run Code Online (Sandbox Code Playgroud) android lostfocus lost-focus android-softkeyboard android-view
好吧,我有一个具有IsEditing属性的控件,为了参数的缘故,它有一个默认模板,通常是一个文本块,但是当IsEditing为true时,它会在文本框中交换以进行就地编辑.现在当控件失去焦点时,如果它仍在编辑,它应该退出编辑模式并在TextBlock模板中交换回来.非常直接,对吧?
想想在Windows资源管理器或桌面上重命名文件的行为(这与我所知道的相同......)这就是我们想要的行为.
问题是您不能使用LostFocus事件,因为当您切换到另一个窗口(或作为FocusManager的元素)时,LostFocus不会触发,因为控件仍具有逻辑焦点,因此无法工作.
如果您改为使用LostKeyboardFocus,虽然这确实解决了"其他FocusManager"问题,但现在您有了一个新问题:当您进行编辑并右键单击文本框以显示上下文菜单时,因为上下文菜单现在有键盘焦点,您的控件失去键盘焦点,退出编辑模式并关闭上下文菜单,使用户感到困惑!
现在我已经尝试设置一个标志,在菜单打开之前忽略LostKeyboardFocus,然后在LostKeyboardFocus事件中使用该fiag来确定是否将其踢出编辑模式,但是如果菜单打开并且我点击其他位置应用程序,因为控件本身不再有键盘焦点(菜单有它)控件永远不会获得另一个LostKeyboardFocus事件,因此它仍然处于编辑模式.(我可能必须在菜单关闭时添加一个检查以查看焦点是什么,然后手动将其从EditMode中踢出来,如果它不是控件.这看起来很有希望.)
那么......任何人都知道如何成功编码这种行为?
标记
一,标准信息:
VS2010 Ultimate
Win7 Ultimate x64
WPF应用程序
WPF上下文菜单:
<ContextMenu x:Key="RightClickSystemTray" Placement="MousePoint">
<MenuItem Header="Exit" Click="Menu_Exit"></MenuItem>
</ContextMenu>
Run Code Online (Sandbox Code Playgroud)
显示它的代码:
void _notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
ContextMenu menu = (ContextMenu)this.FindResource("RightClickSystemTray");
menu.IsOpen = true;
}
}
Run Code Online (Sandbox Code Playgroud)
上下文菜单是在XAML中构建的WPF ContextMenu.系统托盘中的通知图标是表单通知图标(我不知道本机WPF通知图标).因此,不使用notifyicon.ContextMenu属性.上面的代码工作正常.当用户右键单击通知图标时,上下文菜单会显示它应该显示的内容.
我遇到的问题是让ContextMenu在我想要的时候消失.只要你点击WPF应用程序中的某个地方,它就会消失.此行为是自动的.但是,如果用户点击其他地方,例如任务栏,则菜单不会消失."LostFocus"事件不会触发,因为这些类型的事件仅在元素失去焦点到同一应用程序中的另一个元素时触发.就应用而言,ContextMenu永远不会失去焦点."Deactivated"是我试图使用的另一个事件.此时我应该澄清应用程序有一个"接近托盘"选项,因此应用程序可以在用户有机会右键单击并显示菜单之前关闭并触发已停用的事件.当菜单出现时,应用程序不会重新激活,因此当我单击任务栏时,甚至不会激活停用的应用程序.
最后,问题.当用户点击它时,如何让我的上下文菜单消失,即使用户点击的位置不在创建上下文菜单的应用程序中?
我的WPF应用程序中有一个搜索屏幕.该屏幕在TabControl的TabItem中实现为UserControl.当用户切换到"搜索"选项卡时,我希望焦点进入一个特定字段.
所以我在Xaml中的UserControl标签中添加了一个Loaded事件处理程序,并且我调用了控件的Focus方法,我想在Loaded事件处理程序中获得初始焦点.这很有效,直到我升级了今天使用的Telerik控件库.现在,当我切换到"搜索"选项卡时,焦点不在我想要的字段中,但我无法分辨出哪个控件具有焦点.
由于其他原因,我想要拥有焦点的字段已经有GotFocus和LostFocus事件处理程序.我记得在Win Forms中,LostFocus事件处理程序参数告诉您哪个控件将获得焦点.所以我在LostFocus处理程序中放置了一个断点,并发现WPF中LostFocus事件处理程序的参数不包含该信息.
如何在不在我的UserControl中的每个控件上放置GotFocus处理程序的情况下找出焦点的位置?
托尼
我有一个用户控件,有几个子元素,包括复选框和文本框.
我想仅在整个用户控件上丢失焦点时触发我的用户控件的LostFocus事件(例如,单击用户控件外部的按钮).
目前,当我在用户控件的子元素之间移动时,LostFocus事件也会触发,例如从一个文本框移动到另一个文本框.
我有文本框,当我lostFocus被解雇时我正在更改其中的文本,但这也会激活textChanged我正在处理的事件,但是我不想在这种情况下解雇它,我怎么能在这里禁用它?
这个想法bool很好,但我有几个文本框,我对所有这些都使用相同的事件,所以它并不像我想要的那样完全正常工作.
现在它正在运作!:
private bool setFire = true;
private void mytextbox_LostFocus(object sender, RoutedEventArgs e)
{
if (this.IsLoaded)
{
System.Windows.Controls.TextBox textbox = sender as System.Windows.Controls.TextBox;
if(textbox.Text.ToString().Contains('.'))
{
textbox.Foreground = new SolidColorBrush(Colors.Gray);
textbox.Background = new SolidColorBrush(Colors.White);
setFire = false;
textbox.Text = "something else";
setFire = true;
}
}
}
private void mytextbox_TextChanged(object sender, TextChangedEventArgs e)
{
if ((this.IsLoaded) && setFire)
{
System.Windows.Controls.TextBox textbox = sender as System.Windows.Controls.TextBox;
if(textbox.Text.ToString().Contains('.'))
{
textbox.Foreground = new SolidColorBrush(Colors.White); …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
<div id="showReplyDiv">
<form id="test">
<div>
<textarea id="articleEditor" name="articleVO.articleC"></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'articleEditor',{customConfig : '/Forum/ckeditor/replyCKEditor.js'});
</script>
</div>
<div id="buttonArea">
<input type="button" id="doReply" value="submit"/>
<input type="button" id="cancel" value="cancel"/>
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要它,以便当用户单击此之外的任何位置时ckEditor,我可以隐藏它。
我在使用带有html输入文本的cordova 2.7在iOS 7上开发手机间隙应用程序时遇到了问题.当我选择输入文本时,键盘会弹出.但由于焦点丢失,无法输入任何内容.我必须再次选择输入文字.
谁可以帮我这个事.
我只是想知道,在制作游戏时,我注意到当我的游戏具有焦点时,IsRunningSlowly的GameTime值会返回false(就像它应该的那样),但是当我更改应用程序时,它会变为true.我甚至做了一个空的游戏,即使失去焦点,IsRunningSlowly的GameTime值也会返回true.我想知道它为什么这样做?它只是我的电脑,还是XNA的创造者是这样设计的?帧速率似乎很好,但值是真的.没什么大不了的,我真的好奇!
[空游戏]
public class Game1 : Microsoft.Xna.Framework.Game
{
#region Constuctors
public Game1()
{
this.GraphicsManager = new Microsoft.Xna.Framework.GraphicsDeviceManager(this);
this.Content.RootDirectory = "Content";
}
#endregion
#region Overrides
protected override void LoadContent()
{
this.SpriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(this.GraphicsDevice);
base.LoadContent();
}
protected override void Update(Microsoft.Xna.Framework.GameTime GameTime)
{
System.Console.WriteLine(GameTime.IsRunningSlowly);
Microsoft.Xna.Framework.Input.KeyboardState Keyboard = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (Keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) this.Exit();
base.Update(GameTime);
}
protected override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
{
GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
base.Draw(gameTime);
}
#endregion
#region Variables
private Microsoft.Xna.Framework.GraphicsDeviceManager GraphicsManager { get; set; }
private Microsoft.Xna.Framework.Graphics.SpriteBatch SpriteBatch { get; set; }
#endregion
}
Run Code Online (Sandbox Code Playgroud) 我是C#的初学者,我正在开发一个基本的应用程序.
我想检查文本框的值是否为包含以下代码的数字:
private void check_value(object sender)
{
TextBox tb = (TextBox)sender ;
if (!Utility.isNumeric(tb.Text)){
MessageBox.Show(tb.Text.Length.ToString());
tb.Focus();
}
}
private void Amount_1_LostFocus(object sender, RoutedEventArgs e)
{
check_value(sender);
}
Run Code Online (Sandbox Code Playgroud)
当我在文本框中输入一个字母时,有一个无限循环,似乎tb.Focus()实际上导致LostFocus事件被递归调用.我不明白为什么调用对象的Focus方法会触发同一对象的LostFocus事件.
我正在使用 LostFocus 事件验证两个文本字段,如下所示:
textRegNo.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
regNo1=textRegNo.getText();
Pattern pattern1 = Pattern.compile("^[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{4}$");
Matcher matcher1 = pattern1.matcher(regNo1);
if (!matcher1.find()){
JOptionPane.showMessageDialog(null, "Invalid Vehicle No!!!\n Vehicle no should be of the form MH 03 KS 2131!!");
}
}
@Override
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
};
});
textMobNo.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
mobNo1=textMobNo.getText();
Pattern pattern2 = …Run Code Online (Sandbox Code Playgroud) lostfocus ×12
wpf ×5
c# ×3
lost-focus ×3
android ×2
textbox ×2
android-view ×1
ckeditor ×1
contextmenu ×1
cordova ×1
events ×1
focus ×1
focusmanager ×1
forms ×1
ios ×1
java ×1
jquery ×1
notifyicon ×1
regex ×1
swing ×1
textchanged ×1
textfield ×1
validation ×1
xna ×1