1. 程式人生 > >頻道管理 簡單!!!

頻道管理 簡單!!!

佈局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:gravity="center"/>

</android.support.constraint.ConstraintLayout>

主頁面程式碼

package com.bw.ymy.pindao;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.andy.library.ChannelActivity;
import com.andy.library.ChannelBean;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private Button button;
    private List<ChannelBean> list;
    private String jsonStr;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button(v);
            }
        });
    }

    private void button(View view) {
        if (list==null){
            list=new ArrayList<>();
            list.add(new ChannelBean("熱點",true));
            list.add(new ChannelBean("袁大頭",true));
            list.add(new ChannelBean("邵處長",true));
            list.add(new ChannelBean("二黑",true));
            list.add(new ChannelBean("秦老鼠",true));
            list.add(new ChannelBean("舒克",false));
            list.add(new ChannelBean("貝塔",false));
            list.add(new ChannelBean("二嘎子",false));
            list.add(new ChannelBean("biubiubiu",false));
            ChannelActivity.startChannelActivity(this,list);
        }
        else if (jsonStr!=null){
            ChannelActivity.startChannelActivity(this,jsonStr);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==ChannelActivity.REQUEST_CODE&&resultCode==ChannelActivity.RESULT_CODE){
            jsonStr=data.getStringExtra(ChannelActivity.RESULT_JSON_KEY);
        }
    }
}

依賴:

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

implementation 'com.github.andyoom:draggrid:v1.0.1'