본문 바로가기
Android

단말기 하드키 조작과 listview focusing

by Birthmark 2021. 1. 7.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
       case AppButtonManager.BUTTON_USER:      //右釦を押した時
                        //右側釦が押された時
                        if (newState) {
                            Button_right_Enb = false;
 
                            listView.post(new Runnable() {
                                public void run() {
                                    final int firstListItemPosition = listView.getFirstVisiblePosition();
                                    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
                                    //ハードキーの最初押し
                                    if (first) {
                                        listView.getChildAt(0).requestFocusFromTouch();
                                        listView.setSelectionFromTop(010);
                                        first = false;
                                    } else {
                                        position++;
                                        if (position == listView.getCount()) {
                                            position = 0;
                                            listView.smoothScrollToPosition(position);
                                            listView.getChildAt(0).requestFocusFromTouch();
                                            listView.setSelection(0);
                                        } else {
 
                                            if (position < firstListItemPosition || position > lastListItemPosition) {
                                                position = firstListItemPosition;
                                                listView.setSelection(position);
                                            } else {    //目視
                                                final int childIndex = position - firstListItemPosition;
                                                listView.getChildAt(childIndex).requestFocusFromTouch();
                                                listView.setSelectionFromTop(position, 340);
                                            }
 
                                        }
 
 
                                        Log.i("##""right pushed: " + position);
                                    }
                                }
                            });
 
                        } else {
                            Button_right_Enb = true;   //釦が再び取得出来る状態にする
                        }
                        break;
 
                    case AppButtonManager.BUTTON_SIDE:      //左釦を押した時
                        //左側釦が押された時
 
                        if (newState) {
                            Button_left_Enb = false;
                            listView.post(new Runnable() {
                                public void run() {
 
                                    final int firstListItemPosition = listView.getFirstVisiblePosition();
                                    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
 
 
                                    //ハードキーの最初押しでフォーカス取得
                                    if (first) {
                                        listView.getChildAt(0).requestFocusFromTouch();
                                        listView.setSelectionFromTop(0,45);
                                        first = false;
                                    } else {
 
                                        position--;
                                        if (position < 0 ) {    //循環のため
                                            position = listView.getCount() - 1;
                                        }
 
                                        if (position < firstListItemPosition || position > lastListItemPosition) {
                                            if (position != listView.getCount() - 1) {
                                                position = firstListItemPosition;
                                            }
 
                                        }
                                        else {
                                            final int childIndex = position - firstListItemPosition;
                                            listView.getChildAt(childIndex).requestFocusFromTouch();
                                        }
                                        listView.setSelectionFromTop(position,340);
 
                                        Log.i("##""left pushed:" + position);
                                    }
                                }
 
                            });
                        }
                        //左側釦が離れた時
                        else{
                            Button_left_Enb = true;   //釦が再び取得出来る状態にする
                        }
                        break;
cs

보이지 않는 리스트 뷰 항목에 포커싱 하기 위해서는!

1
2
3
  int childIndex = mPosition - listView.getFirstVisiblePosition();
        listView.setSelectionFromTop(mPosition, 340);
        listView.getChildAt(childIndex).requestFocusFromTouch();
cs

'Android' 카테고리의 다른 글

ListView 스크롤해도 button selected 유지하기  (0) 2021.01.21
레이아웃과 포커싱  (0) 2021.01.20
Big decimal  (0) 2020.12.21
How to get a decimal point using EditText TextWatcher  (0) 2020.12.18
AES128 암호화  (0) 2020.12.18

댓글