我尝试获得软键盘状态,(显示或隐藏) 使用onConfigurationChanged(此处:http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange)
但它对我不起作用。我不知道。 (我也已经尝试过hardKeyboardHidden和keyboard-config的价值)
请检查我的代码。
的AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:configChanges="keyboardHidden"
android:windowSoftInputMode="adjustResize"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.keyboardHidden== Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
} else if (newConfig.keyboardHidden== Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
}
}
只是简单地在activity_main.xml中添加了EditText
<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"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
那么如何解决这个问题?
答案 0 :(得分:1)
此方法使用// An function that may error and throw exception.
function funcThatThrows(test) {
throw(`oops - error in test ${test}`);
}
function errHandler(exception) {
console.log('We got an exception: ', exception);
}
// Expect: We got an exception: oops - error in test 1
Promise.resolve(1).then(funcThatThrows).catch(errHandler);
// Is the same as below, the errHandler tries to catch any unhandled error
// from previous result.
// Expect: We got an exception: oops - error in test 2
Promise.resolve(2).then(funcThatThrows, null).then(null, errHandler);
// If put the function and handler in the same then, the exception won't be caught.
// Expect: Uncaught (in promise) oops - error in test 3
Promise.resolve(3).then(funcThatThrows, errHandler);
。它会检查活动屏幕是否较小。
答案 1 :(得分:1)
以下解决方案如何?
if exists (select * from INFORMATION_SCHEMA.ROUTINES where ROUTINE_NAME = 'fn_Split' )
drop function [dbo].[fn_Split]
go
CREATE FUNCTION fn_Split(@Text varchar(MAX), @Delimiter varchar(20) = ',')
RETURNS @Strings TABLE
(
Position int IDENTITY PRIMARY KEY,
Value varchar(MAX)
)
AS
BEGIN
DECLARE @Index int = -1
WHILE (LEN(@Text) > 0)
BEGIN
SET @Index = CHARINDEX(@Delimiter , @Text)
IF (@Index = 0) AND (LEN(@Text) > 0)
BEGIN
INSERT INTO @Strings VALUES (@Text)
BREAK
END
IF (@Index > 1)
BEGIN
INSERT INTO @Strings VALUES (LEFT(@Text, @Index - 1))
SET @Text = RIGHT(@Text, (LEN(@Text) - @Index))
END
ELSE
SET @Text = RIGHT(@Text, (LEN(@Text) - @Index))
END
RETURN
END
go
if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'ContentKeyword')
drop table ContentKeyword;
go
Create Table ContentKeyword
(
[KeywordId] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Name] [nvarchar](500) NOT NULL
)
go
if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'ContentKeyword')
drop table JobKeyword;
go
Create Table JobKeyword
(
[KeywordId] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Name] [nvarchar](500) NOT NULL
)
go
if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'ContentKeyword')
drop table CategoryGroup;
go
Create Table CategoryGroup
(
[KeywordId] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Name] [nvarchar](500) NOT NULL
)
go
--Insert dummy data
insert into CategoryGroup(Name) values('First value')
go
select S.Value from dbo.fn_Split('1,2,3,4,5', ',') S
left outer join ContentKeyword CK on CK.KeywordId = s.Value
left outer join JobKeyword JK on JK.KeywordId = s.Value
left outer join CategoryGroup JG on JG.KeywordId = s.Value
where
(1 = 1)
and CK.KeywordId is null
and JK.KeywordId Is null
and JG.KeywordId is null