仿網(wǎng)易類型管理洋机,點(diǎn)擊長按拖到標(biāo)簽移動浇冰,點(diǎn)擊右上角按鈕保存

1贬媒、xml文件中設(shè)置

<Button

? ? ? ? android:id="@+id/btn_zxing"

? ? ? ? android:text="二維碼"

? ? ? ? android:layout_width="wrap_content"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? />

? ? <ImageView

? ? ? ? android:id="@+id/img"

? ? ? ? android:layout_margin="100dp"

? ? ? ? android:layout_width="300dp"

? ? ? ? android:layout_height="300dp"/>

? ? <ScrollView

? ? ? ? android:layout_width="match_parent"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:padding="20dp"

? ? ? ? android:scrollbars="none"

? ? ? ? app:layout_constraintEnd_toEndOf="parent"

? ? ? ? app:layout_constraintStart_toStartOf="parent"

? ? ? ? app:layout_constraintTop_toBottomOf="@+id/include2">

? ? ? ? <LinearLayout

? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:orientation="vertical">

? ? ? ? ? ? <LinearLayout

? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? ? ? android:orientation="vertical">

? ? ? ? ? ? ? ? <TextView

? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"

? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? ? ? ? ? android:padding="10dp"

? ? ? ? ? ? ? ? ? ? android:text="已添加驗(yàn)證類型(已添加的類型將會在首頁展示)"

? ? ? ? ? ? ? ? ? ? android:textColor="@color/black" />

? ? ? ? ? ? ? ? <View

? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="0.5dp"

? ? ? ? ? ? ? ? ? ? />

? ? ? ? ? ? ? ? <androidx.recyclerview.widget.RecyclerView

? ? ? ? ? ? ? ? ? ? android:id="@+id/certification_manage_add_rv"

? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? ? ? ? ? android:layout_margin="10dp" />

? ? ? ? ? ? </LinearLayout>

? ? ? ? ? ? <LinearLayout

? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? ? ? android:layout_marginTop="30dp"

? ? ? ? ? ? ? ? android:orientation="vertical">

? ? ? ? ? ? ? ? <TextView

? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"

? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? ? ? ? ? android:padding="10dp"

? ? ? ? ? ? ? ? ? ? android:text="可添加驗(yàn)證類型"

? ? ? ? ? ? ? ? ? ? android:textColor="@color/black" />

? ? ? ? ? ? ? ? <View

? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="0.5dp"

? ? ? ? ? ? ? ? ? ? />

? ? ? ? ? ? ? ? <androidx.recyclerview.widget.RecyclerView

? ? ? ? ? ? ? ? ? ? android:id="@+id/certification_manage_can_add_rv"

? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? ? ? ? ? android:layout_margin="10dp" />

? ? ? ? ? ? </LinearLayout>

? ? ? ? </LinearLayout>

? ? </ScrollView>

? ? <com.google.android.material.floatingactionbutton.FloatingActionButton

? ? ? ? android:id="@+id/fab"

? ? ? ? android:layout_width="wrap_content"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:layout_gravity="bottom|end"

? ? ? ? android:layout_margin="@dimen/fab_margin"

? ? ? ? app:srcCompat="@android:drawable/ic_dialog_email" />

第二步:設(shè)置布局管理器

/**

? ? ? ? * 已添加

? ? ? ? */

? ? ? ? mCertificationManageAddRv.setLayoutManager(new GridLayoutManager(this, 3));

//? ? ? ? certificationManageAddRv.addItemDecoration(new GridItemDecoration(30));

? ? ? ? mAddAdapter = new CertificationManageadapter(addDatas, -1);

? ? ? ? mCertificationManageAddRv.setAdapter(mAddAdapter);

? ? ? ? mAddAdapter.setOnItemClickListener(setAdapterItemClick(0));

? ? ? ? /**

? ? ? ? * 可添加

? ? ? ? */

? ? ? ? mCertificationManageCanAddRv.setLayoutManager(new GridLayoutManager(this, 3));

//? ? ? ? certificationManageCanAddRv.addItemDecoration(new GridItemDecoration(30));

? ? ? ? mCanAddAdapter = new CertificationManageadapter(canAddDatas, -1);

? ? ? ? mCertificationManageCanAddRv.setAdapter(mCanAddAdapter);

? ? ? ? mCanAddAdapter.setOnItemClickListener(setAdapterItemClick(1));

第三步:設(shè)置適配器

1、先在 build.gradle(Project:XXXX) 的 repositories 添加:

? allprojects {

? ? ? ? repositories {

? ? ? ? ? ? ...

? ? ? ? ? ? maven { url "https://jitpack.io" }

? ? ? ? }

? ? }

2肘习、在 build.gradle(Module:app) 的 dependencies 添加:

dependencies {

? ? ? ? ? ? compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.28'

? ? }

3际乘、創(chuàng)建適配器

public class CertificationManageadapter extends BaseQuickAdapter<CertificationManageBean, BaseViewHolder> {

? ? public void setAdapterType(int adapterType) {

? ? ? ? this.adapterType = adapterType;

? ? }

? ? /**

? ? * 0 已添加 1可添加

? ? */

? ? private int adapterType;

? ? public CertificationManageadapter(@Nullable List<CertificationManageBean> data, int type) {

? ? ? ? super(R.layout.item_certification_manage, data);

? ? ? ? adapterType = type;

? ? }

? ? @Override

? ? protected void convert(BaseViewHolder helper, CertificationManageBean item) {

? ? ? ? helper.setText(R.id.certification_manage_tv_name, item.getName());

? ? ? ? if (adapterType == -1) {

? ? ? ? ? ? helper.getView(R.id.certification_manage_img).setVisibility(View.GONE);

? ? ? ? } else {

? ? ? ? ? ? helper.getView(R.id.certification_manage_img).setVisibility(View.VISIBLE);

? ? ? ? ? ? if (adapterType == 0) {

? ? ? ? ? ? ? ? helper.setImageResource(R.id.certification_manage_img, R.mipmap.ic_launcher);

? ? ? ? ? ? } else if (adapterType == 1) {

? ? ? ? ? ? ? ? helper.setImageResource(R.id.certification_manage_img, R.mipmap.ic_launcher);

? ? ? ? ? ? }

? ? ? ? }

? ? }

}

注意:CertificationManageBean是個(gè)實(shí)體類

public class CertificationManageBean {

? ? private int id;

? ? private String name;

? ? public CertificationManageBean(int id, String name) {

? ? ? ? this.id = id;

? ? ? ? this.name = name;

? ? }

? ? public int getId() {

? ? ? ? return id;

? ? }

? ? public String getName() {

? ? ? ? return name;

? ? }

}

布局文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

? ? xmlns:android="http://schemas.android.com/apk/res/android"

? ? xmlns:tools="http://schemas.android.com/tools"

? ? android:id="@+id/main_cl"

? ? android:layout_width="match_parent"

? ? android:layout_height="wrap_content"

? ? android:gravity="center"

? ? android:layout_margin="5dp"

? ? android:orientation="horizontal"

? ? android:padding="6dp">

? ? <TextView

? ? ? ? android:id="@+id/certification_manage_tv_name"

? ? ? ? android:layout_width="wrap_content"

? ? ? ? android:layout_weight="1"

? ? ? ? android:textSize="12sp"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:layout_alignParentStart="true"

? ? ? ? android:layout_toStartOf="@+id/certification_manage_img"

? ? ? ? android:gravity="center_horizontal"

? ? ? ? tools:text="TextView"

? ? ? ? android:layout_alignParentLeft="true"

? ? ? ? android:layout_toLeftOf="@+id/certification_manage_img" />

? ? <ImageView

? ? ? ? android:id="@+id/certification_manage_img"

? ? ? ? android:layout_width="10dp"

? ? ? ? android:layout_height="10dp"

? ? ? ? android:layout_alignParentEnd="true"

? ? ? ? android:layout_marginStart="5dp"

? ? ? ? android:src="@mipmap/ic_launcher"

? ? ? ? android:layout_alignParentRight="true"

? ? ? ? android:layout_marginLeft="5dp" />

</LinearLayout>

第三步:創(chuàng)建適配器的監(jiān)聽方法,創(chuàng)建變量

? /**

? ? * 已添加驗(yàn)證類型

? ? */

? ? List<CertificationManageBean> addDatas = new ArrayList<>();

? ? /**

? ? * 可添加驗(yàn)證類型

? ? */

? ? boolean isOperating;

private BaseQuickAdapter.OnItemClickListener setAdapterItemClick(final int type) {

? ? ? ? return new BaseQuickAdapter.OnItemClickListener() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

? ? ? ? ? ? ? ? if (isOperating) {

? ? ? ? ? ? ? ? ? ? if (type == 0) {

? ? ? ? ? ? ? ? ? ? ? ? canAddDatas.add(addDatas.get(position));

? ? ? ? ? ? ? ? ? ? ? ? addDatas.remove(position);

? ? ? ? ? ? ? ? ? ? ? ? mAddAdapter.notifyItemRemoved(position);

? ? ? ? ? ? ? ? ? ? ? ? mCanAddAdapter.notifyItemChanged(canAddDatas.size() - 1);

? ? ? ? ? ? ? ? ? ? } else if (type == 1) {

? ? ? ? ? ? ? ? ? ? ? ? addDatas.add(canAddDatas.get(position));

? ? ? ? ? ? ? ? ? ? ? ? canAddDatas.remove(position);

? ? ? ? ? ? ? ? ? ? ? ? mCanAddAdapter.notifyItemRemoved(position);

? ? ? ? ? ? ? ? ? ? ? ? mAddAdapter.notifyItemChanged(addDatas.size() - 1);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? };

? ? }

第四步:設(shè)置右上角按鈕的監(jiān)聽

? mBtnZxing.setOnClickListener(new View.OnClickListener() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onClick(View v) {

? ? ? ? ? ? ? ? if (isOperating){

? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity2.this, ""+addDatas.toString(), Toast.LENGTH_SHORT).show();

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? isOperating =! isOperating;

? ? ? ? ? ? ? ? if (isOperating) {

? ? ? ? ? ? ? ? ? ? mBtnZxing.setText("保存");

? ? ? ? ? ? ? ? ? ? mAddAdapter.setAdapterType(0);

? ? ? ? ? ? ? ? ? ? mAddAdapter.notifyDataSetChanged();

? ? ? ? ? ? ? ? ? ? mCanAddAdapter.setAdapterType(1);

? ? ? ? ? ? ? ? ? ? mCanAddAdapter.notifyDataSetChanged();

? ? ? ? ? ? ? ? }else {

? ? ? ? ? ? ? ? ? ? mBtnZxing.setText("類型管理");

? ? ? ? ? ? ? ? ? ? mAddAdapter.setAdapterType(-1);

? ? ? ? ? ? ? ? ? ? mAddAdapter.notifyDataSetChanged();

? ? ? ? ? ? ? ? ? ? mCanAddAdapter.setAdapterType(-1);

? ? ? ? ? ? ? ? ? ? mCanAddAdapter.notifyDataSetChanged();

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? });

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末井厌,一起剝皮案震驚了整個(gè)濱河市蚓庭,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌仅仆,老刑警劉巖器赞,帶你破解...
    沈念sama閱讀 219,589評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異墓拜,居然都是意外死亡港柜,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,615評論 3 396
  • 文/潘曉璐 我一進(jìn)店門咳榜,熙熙樓的掌柜王于貴愁眉苦臉地迎上來夏醉,“玉大人,你說我怎么就攤上這事涌韩∨先幔” “怎么了?”我有些...
    開封第一講書人閱讀 165,933評論 0 356
  • 文/不壞的土叔 我叫張陵臣樱,是天一觀的道長靶擦。 經(jīng)常有香客問我,道長雇毫,這世上最難降的妖魔是什么玄捕? 我笑而不...
    開封第一講書人閱讀 58,976評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮棚放,結(jié)果婚禮上枚粘,老公的妹妹穿的比我還像新娘。我一直安慰自己飘蚯,他們只是感情好馍迄,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,999評論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著孝冒,像睡著了一般柬姚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上庄涡,一...
    開封第一講書人閱讀 51,775評論 1 307
  • 那天量承,我揣著相機(jī)與錄音,去河邊找鬼穴店。 笑死撕捍,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的泣洞。 我是一名探鬼主播忧风,決...
    沈念sama閱讀 40,474評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼球凰!你這毒婦竟也來了狮腿?” 一聲冷哼從身側(cè)響起腿宰,我...
    開封第一講書人閱讀 39,359評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎缘厢,沒想到半個(gè)月后吃度,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,854評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡贴硫,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,007評論 3 338
  • 正文 我和宋清朗相戀三年椿每,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片英遭。...
    茶點(diǎn)故事閱讀 40,146評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡间护,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出挖诸,到底是詐尸還是另有隱情汁尺,我是刑警寧澤,帶...
    沈念sama閱讀 35,826評論 5 346
  • 正文 年R本政府宣布多律,位于F島的核電站均函,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏菱涤。R本人自食惡果不足惜苞也,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,484評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望粘秆。 院中可真熱鬧如迟,春花似錦、人聲如沸攻走。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,029評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽昔搂。三九已至玲销,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間摘符,已是汗流浹背贤斜。 一陣腳步聲響...
    開封第一講書人閱讀 33,153評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留逛裤,地道東北人瘩绒。 一個(gè)月前我還...
    沈念sama閱讀 48,420評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像带族,于是被迫代替她去往敵國和親锁荔。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,107評論 2 356

推薦閱讀更多精彩內(nèi)容