xml如下。
我想实现这样的功能:当我点击edittext时,软输入显示。
当我滚动(不滚动到OnScrollListener.SCROLL_STATE_IDLE
状态)列表时,软输入隐藏。
我使用android:windowSoftInputMode="adjustResize"
。
答案 0 :(得分:10)
使用this link检测您的滚动,
它实现onScrollListener
,您将设置为ListView
,并在其onScrollStateChanged()
中将此代码放入您的< - p>
setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState !=0){
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
});
答案 1 :(得分:1)
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(absListView.getApplicationWindowToken(), 0);
给出了AS中的错误... 在onScrollStateChange
中使用它@Component({
template: `
<div *ngFor="let group of grouped">
<ng-container *ngFor="let el of group">
{{ el }}
</ng-container>
</div>
`,
selector: 'test'
})
export class TestComponent implements OnInit {
public grouped: number[][] = [];
// Don't make it zero
private numPerGroup = 3;
ngOnInit(): void {
let testArray: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let group: number[];
for (let i = 0; i < testArray.length; i++) {
if (!(i % this.numPerGroup)) {
this.grouped.push(group = []);
}
group.push(testArray[i]);
}
}
}