package com.andyiac.button.selecter;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import java.util.ArrayList;

public class MainActivity extends Activity {
    private FlowLayout flowLayout;

    private String[] mVals = new String[]
            {"Hello", "Android", "Weclome Hi ", "Button", "TextView", "Hello",
                    "Android", "Weclome", "Button ImageView", "TextView", "Helloworld",
                    "Android", "Weclome Hello", "Button Text", "TextView"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        flowLayout = (FlowLayout) findViewById(R.id.flow_layout);
        initData();
    }


    private ArrayList<String> lables = new ArrayList<String>();

    public void initData() {
        LayoutInflater mInflater = LayoutInflater.from(this);

//        for (int i = 0; i < mVals.length; i++) {
//            lables.add(mVals[i]);
//        }

        // todo 传给 SelectView 一个空的list 点击就增加和删除

        // todo

        for (int i = 0; i < mVals.length; i++) {
            final SelectView sv = (SelectView) mInflater.inflate(R.layout.select_view_item, flowLayout, false);
            sv.setText(mVals[i]);
            flowLayout.addView(sv);
            sv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    lables = sv.mToggle(lables);
                    Log.e("TAG", "=====lables====>" + lables);
                }
            });

        }


//        for (int i = 0; i < mVals.length; i++) {
//
//            final SelectView tv = (SelectView) mInflater.inflate(R.layout.select_view_item, flowLayout, false);
//            tv.setText(mVals[i]);
//            flowLayout.addView(tv);
//            tv.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (lables.size() >= 5 && !tv.mToggle().toString().startsWith("_remove")) {
//                        Toast.makeText(MainActivity.this, "最多添加5个标签", Toast.LENGTH_SHORT).show();
//                        return;
//                    }
//                    String lable = tv.mToggle();
//                    lables.add(lable);
//
//                    if (lable.startsWith("_remove")) {
//                        lables.remove(lable.substring("_remove".length() - 1, lable.length() - 1));
//                        Log.e("TAG", "=====lables===>>" + lables);
//                        Toast.makeText(MainActivity.this, "删除标签" + lable, Toast.LENGTH_SHORT).show();
//                    }
//
//
//                }
//            });
//        }
    }

}

@@ -1008,110 +1008,8 @@
 %0D%0A%0D%0A
-//        for (int i = 0; i %3C mVals.length; i++) %7B%0D%0A//            lables.add(mVals%5Bi%5D);%0D%0A//        %7D%0D%0A
 %0D%0A  
@@ -1061,27 +1061,8 @@
 %0D%0A%0D%0A
-        // todo%0D%0A%0D%0A
     
@@ -1599,1181 +1599,8 @@
 %0D%0A%0D%0A
-%0D%0A//        for (int i = 0; i %3C mVals.length; i++) %7B%0D%0A//%0D%0A//            final SelectView tv = (SelectView) mInflater.inflate(R.layout.select_view_item, flowLayout, false);%0D%0A//            tv.setText(mVals%5Bi%5D);%0D%0A//            flowLayout.addView(tv);%0D%0A//            tv.setOnClickListener(new View.OnClickListener() %7B%0D%0A//                @Override%0D%0A//                public void onClick(View v) %7B%0D%0A//                    if (lables.size() %3E= 5 && !tv.mToggle().toString().startsWith(%22_remove%22)) %7B%0D%0A//                        Toast.makeText(MainActivity.this, %22%E6%9C%80%E5%A4%9A%E6%B7%BB%E5%8A%A05%E4%B8%AA%E6%A0%87%E7%AD%BE%22, Toast.LENGTH_SHORT).show();%0D%0A//                        return;%0D%0A//                    %7D%0D%0A//                    String lable = tv.mToggle();%0D%0A//                    lables.add(lable);%0D%0A//%0D%0A//                    if (lable.startsWith(%22_remove%22)) %7B%0D%0A//                        lables.remove(lable.substring(%22_remove%22.length() - 1, lable.length() - 1));%0D%0A//                        Log.e(%22TAG%22, %22=====lables===%3E%3E%22 + lables);%0D%0A//                        Toast.makeText(MainActivity.this, %22%E5%88%A0%E9%99%A4%E6%A0%87%E7%AD%BE%22 + lable, Toast.LENGTH_SHORT).show();%0D%0A//                    %7D%0D%0A//%0D%0A//%0D%0A//                %7D%0D%0A//            %7D);%0D%0A//        %7D%0D%0A
     

reformat code