๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Android

Android::SwipeMenuList

by ๋„์บ๋ฆฌ๐Ÿฑ 2020. 8. 1.
๋ฐ˜์‘ํ˜•

 


<button

    android:onClick = "onClick"

/>

→ ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•˜๋ฉด์„œ button์— ์ด๋ฒคํŠธ๋ฅผ ๋“ฑ๋ก์‹œํ‚ค๋Š” ๊ฒƒ. " "์•ˆ์— ๋“ค์–ด๊ฐ€๋Š”๊ฒŒ java ์—์„œ ์‚ฌ์šฉํ•  ํ•จ์ˆ˜ ๋ช….

๋งŒ์•ฝ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ํ•ด๋‹นํ•˜๋Š” " "ํ•จ์ˆ˜๋ฅผ ์ฐพ์•„ ์‹คํ–‰์„ ํ•˜๊ฒŒ ๋œ๋‹ค.

https://copycoding.tistory.com/47


ViewHolder?

๋ทฐ๋“ค์„ ํ™€๋”์— ๊ผฝ์•„ ๋†“๋“ฏ์ด ๋ณด๊ด€ํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋งํ•œ๋‹ค.

๊ฐ๊ฐ์˜ Row๋ฅผ ๊ทธ๋ ค๋‚ผ ๋•Œ, ๊ทธ ์•ˆ์˜ ์œ„์ ฏ๋“ค์˜ ์†์„ฑ์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ํŒจํ„ด.

์ฃผ๋กœ ListView์˜ ํผํฌ๋จผ์Šค๋ฅผ ๋†’์ด๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค.

https://uroa.tistory.com/6

 

↓ ๊ณต์‹ ๋ฌธ์„œ๋„ ์ฐธ๊ณ .

https://developer.android.com/guide/topics/ui/layout/recyclerview#ViewHolder

row, columns ๋งจ๋‚  ํ—ท๊ฐˆ๋ ค์„œ ์ฒจ๋ถ€

 


Dp์™€ PX ์ฐจ์ด 

inma.tistory.com/72

ํ”ฝ์…€์—์„œ ๋””ํ”ผ๋กœ, ๋””ํ”ผ์—์„œ ํ”ฝ์…€๋กœ ๋ฐ”๊ฟ”์ ธ์•ผ ํ•œ๋‹ค. ์ด ๋ณ€ํ™˜์‹์ด ํ•„์š”ํ•œ ์ด์œ ๋Š” ์ž๋ฐ”์—์„œ dp๋ฅผ ์ด์šฉํ•ด์„œ view์˜ ํฌ๊ธฐ๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

DP๋ž€ ์•ˆ๋“œ๋กœ์ด๋“œ์—์„œ ๋‹ค์–‘ํ•œ ๋‹จ๋ง ํ™”๋ฉด ํฌ๊ธฐ๋ฅผ ์„œํฌํŠธํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“  ๋‹จ์œ„๋กœ, 

์ž์‹ ์ด ๋งŒ๋“  ๋ ˆ์ด์•„์›ƒ์ด ๋‹ค์–‘ํ•œ ๋‹จ๋ง์—์„œ ๋™์ผํ•˜๊ฒŒ ๋ณด์ด๊ธฐ ์œ„ํ•ด์„œ๋Š” dp๋ฅผ ์จ์•ผํ•œ๋‹ค.

 


 

SwipMenuList

↓ ๊นƒํ—™

https://github.com/baoyongzhang/SwipeMenuListView

 

โ— ๋™์ž‘ํ•˜๊ฒŒ ํ•˜๊ธฐ

1) build.gradle ์— implementation ์ถ”๊ฐ€

2) ๊ตฌ์กฐ ์ •๋ฆฌ

private List<ApplicationInfo> mAppList;
private AppAdapter mAdapter;
private SwipeMenuListView mListView;

 

protected void onCreate(Bundle savedInstanceState)

{

    mAppList๋ฅผ ์„ค์น˜๋˜์–ด ์žˆ๋Š” ์•ฑ๋“ค๋กœ ์ฑ„์›€

    mListView๋ฅผ xml์—์„œ ์ฐพ์•„์„œ ์—ฐ๊ฒฐ

    mAdapter์€ ์ด๊ฑฐ ๋ฐ–์—์„œ ๋งŒ๋“ค AppAdpater๋กœ ๋งŒ๋“ ๋‹ค. 

    mListView์— mAdapter ์ ์šฉ

 

    ๋ฉ”๋‰ด ํฌ๋ฆฌ์—์ดํ„ฐ ๋งŒ๋“ค๊ธฐ

   mListView์— ๋ฉ”๋‰ด ํฌ๋ฆฌ์—์ดํ„ฐ set ํ•˜๊ธฐ.

    mListView์— ์•„์ดํ…œ ํด๋ฆญ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅํ•˜๋„๋ก ( Menu ํด๋ฆญ์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค. )

   mListView์— SwipeListenr์„ค์ •, menuStateChagneListener ์„ค์ •, long ํด๋ฆญ ๋ฆฌ์Šค๋„ˆ ์„ค์ •

}

 

์œ„์—์„œ ์“ฐ์ผ ํ•จ์ˆ˜๋“ค +ํด๋ž˜์Šค

delete(ApplicationInfo item)

open(ApplicationInfo item)

 

class AppAdapter extends BaseAdapter

class ViewHolder

 

getSwipEnableByPosition(int position)

dp2px(int dp)

boolean onCreateOptionsMenu(Menu menu)

onOptionsItemSelected(@NonNull MenuItem item)

 

 

3) ์‹คํ–‰ํ™”๋ฉด ๋ฐ ์ฝ”๋“œ


 

1. SimpleActivity

 

 

 

2. Menu.xml // ๋ฉ”๋‰ด๋Š” ๋ฉ”๋‰ด ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ  ์•ˆ์— ๋ฉ”๋‰ด ๋ฆฌ์†Œ์ŠคํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์•ผํ•œ๋‹ค.

 

 

3. activity_list

 

4. item_list

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€