«   2018/09   »
            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            
Archives
Today
285
Total
1,153,506
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

Android Swipe 본문

Editor IDE/AndroidStudio

Android Swipe

푸른바람 C/H 2017.01.19 08:30

hudomju/android-swipe-to-dismiss-undo

존재하지 않는 메소드, Override 되지 않는 메소드... 앱 실행까지는 되었지만... 죽어버리는 앱

Swipe to Dismiss for RecyclerView

결국은 Swipe to Dismiss for RecyclerView를 이용해서 Swipe기능을 완성했다. 물론 완벽하게 맘에 들지는 않지만...

public class MainActivity extends AppCompatActivity {
    ....

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        init();
    }

    private void init() {
        SwipeableRecyclerViewTouchListener swipeTouchListener =
            new SwipeableRecyclerViewTouchListener(recyclerView,
                    new SwipeableRecyclerViewTouchListener.SwipeListener() {
                        @Override
                        public boolean canSwipeLeft(int position) {
                            return true;
                        }

                        @Override
                        public boolean canSwipeRight(int position) {
                            return true;
                        }

                        @Override
                        public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] reverseSortedPositions) {
                            for (int position : reverseSortedPositions) {
                                L.d(TAG, "remove Position:" + position );
                                delGame(games.get(position).getDrwNo(), games.get(position).getTR());
                                games.remove(position);
                                gameAdapter.notifyItemRemoved(position);
                            }
                            gameAdapter.notifyDataSetChanged();
                            Toast.makeText(mContext, "삭제 되었습니다.", Toast.LENGTH_SHORT).show();

                            if( games.size() < 1 ){ // 다시 한번 읽기
                                viewGame();
                            }
                        }

                        @Override
                        public void onDismissedBySwipeRight(RecyclerView recyclerView, int[] reverseSortedPositions) {
                            for (int position : reverseSortedPositions) {
                                L.d(TAG, "remove Position:" + position );
                                if( keep == 1 ){
                                    unKeepGame(games.get(position).getDrwNo(), games.get(position).getTR());
                                }else{
                                    keepGame(games.get(position).getDrwNo(), games.get(position).getTR());
                                }
                                games.remove(position);
                                gameAdapter.notifyItemRemoved(position);
                            }
                            gameAdapter.notifyDataSetChanged();

                            if( keep == 1 ){
                                Toast.makeText(mContext, "보관취소 되었습니다.", Toast.LENGTH_SHORT).show();
                            }else{
                                Toast.makeText(mContext, "보관 되었습니다.", Toast.LENGTH_SHORT).show();
                            }

                            if( games.size() < 1 ){ // 다시 한번 읽기 // 다시 한번 읽기
                                viewGame();
                            }
                        }
                    });

        recyclerView.addOnItemTouchListener(swipeTouchListener);
    }

    ...
}

'Editor IDE > AndroidStudio' 카테고리의 다른 글

초기화 값 저장/호출 SharedPreferences  (0) 2017.01.23
네트워크 상태로 자동 실행  (0) 2017.01.20
Android Swipe  (0) 2017.01.19
Android Drawable Shape Syntax  (0) 2017.01.18
android SQLite DB 열기  (0) 2017.01.17
Circle TextView  (0) 2017.01.16
0 Comments
댓글쓰기 폼