仿nice打标签

先上效果图:
这里写图片描述
动态git图
这里写图片描述

github地址:https://github.com/zhiqiangli520210/-nice-
如果觉得还可以话,求各位道友给点个star,谢谢,这样我们都可以为开源共同努力,减少我们的工作时间成本。
首先介绍一下功能点:
本项目是基于PictureView进行优化的
优化亮点:

1.支持点击标签切换方向。

2.支持长按标签删除。

3.支持长按标签移动。

4.支持获取图片所有标签信息集合,包括标签x、y轴坐标,标签内容,标签id,标签方向,标签类型。

5.支持打不同类型的标签,如推荐标签、位置标签、活动标签等。

如果这些功能对你来说有点感兴趣的话,那接下来请看源码

MainActivity:

public class MainActivity extends Activity {

    private PictureTagLayout ptlayout;
    private LinearLayout ll_next;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EventBus.getDefault().register(this);
        initView();
        setListener();
    }

    private void setListener() {
        ll_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击完成时 获取图片上所有标签信息对象集合
                List<SignBean> signBeanList = new ArrayList<SignBean>();
                for (int index = 0; index < ptlayout.getChildCount(); index++) {
                    View childView = ptlayout.getChildAt(index);
                    int w = View.MeasureSpec.makeMeasureSpec(0,
                            View.MeasureSpec.UNSPECIFIED);
                    int h = View.MeasureSpec.makeMeasureSpec(0,
                            View.MeasureSpec.UNSPECIFIED);
                    childView.measure(w, h);
                    int signHeight = childView.getMeasuredHeight();
                    int signWidth = childView.getMeasuredWidth();
                    SignBean bean = new SignBean();
                    //这里需要注意 实际项目中 图片要按比例缩放  标签的位置也要是一个比例值  才能保证在不同尺寸手机上展示的位置不变
//                    标签的x坐标
                    bean.setX((((PictureTagView) childView).getX()+8 ));
//                    标签的y坐标
                    bean.setY(((((PictureTagView) childView).getY())+signHeight/2));
                    //标签名字
                    bean.setDescribe(String.valueOf(((PictureTagView) childView).getShare()));
                    //标签id
                    bean.setBrandId(((PictureTagView) childView).getBrandId());
                    //标签方向
                    bean.setDirection(((PictureTagView) childView).getDirection());
                    //标签类型
                    bean.setType(((PictureTagView) childView).getType());
                    signBeanList.add(bean);
                }
                Log.i("获取图片中标签的所有信息-----",signBeanList.toString());
                finish();
            }
        });
    }

    private void initView() {
        ptlayout = ((PictureTagLayout) findViewById(R.id.ptlayout));
        ll_next = ((LinearLayout) findViewById(R.id.ll_next));

    }

    //用于接收位置、品牌、推荐、历史、活动标签
    @Subscribe(threadMode = MAIN) //注册一个在后台线程执行的方法,用于接收事件
    public void UserEvent(LocTagEvent event) {//参数必须是ClassEvent类型, 否则不会调用此方法
        String name = event.name;
        String type = event.type;
        ptlayout.addData("",name,type);
//        Toast.makeText(context,brandId+"---"+name+"--"+type,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}

activity_main.xml布局中加入一个自定义PictureTagLayout,在其中会加入OnTouch事件,来实现点击添加标签,长按标签进行删除和长按移动等功能:

自定义PictureTagLayout,即标签的父布局:

package com.example.lzq.supperpictagview.view;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.lzq.supperpictagview.ac.ChooseBrandActivity;
import com.example.lzq.supperpictagview.bean.AttentionBrand;
import com.example.lzq.supperpictagview.utils.StringUtils;
import com.example.lzq.supperpictagview.utils.dialog.CustomDialog;
import com.example.lzq.supperpictagview.utils.dialog.CustomEditTextDialog;
/*
* 加左右
*
* */
@SuppressLint("NewApi")
public class PictureTagLayout extends RelativeLayout implements OnTouchListener, View.OnClickListener {
    private static final int CLICKRANGE = 5;
    int startX ;
    int startY ;
    int startTouchViewLeft = 0;
    int startTouchViewTop = 0;
    private View touchView,clickView;
    private Context context;
    private int height;
    private int width;
    private int endX;
    private int endY;
    private int toWhere;
    float xDown,yDown,xUp;
    boolean isLongClickModule = false;
    boolean isLongClicking = false;
    public PictureTagLayout(Context context) {
        super(context, null);
    }
    public PictureTagLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        init();
    }
    private void init(){
        this.setOnTouchListener(this);
    }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            //此处是为了加入长按事件
            xDown= event.getX();
            yDown = event.getY();
            touchView = null;
            if(clickView!=null){
                clickView = null;
            }
            startX = (int) event.getX();
            startY = (int) event.getY();
            if(hasView(startX,startY)){//如果点击位置已经有了
                startTouchViewLeft = touchView.getLeft();
                startTouchViewTop = touchView.getTop();
            } else {
                showPopup();
            }
            Log.i("******点击的位置--x-", startX + "*----y"+startY);
            break;
        case MotionEvent.ACTION_MOVE:
            moveView((int) event.getX(),
                    (int) event.getY());
            if((int) event.getX()>startX){//向右滑动标签view
                toWhere=1;
            }else{
                toWhere=2;
            }
            //此处是为了加入长按事件
            //当滑动时背景为选中状态 //检测是否长按,在非长按时检测
            if(!isLongClickModule)
            {
                isLongClickModule = isLongPressed(xDown, yDown, event.getX(),
                        event.getY(),event.getDownTime() ,event.getEventTime(),300);
            }
            if(isLongClickModule && !isLongClicking){
                if(hasView(startX,startY)){//如果点击位置已经有了
                    //处理长按事件
                    isLongClicking = true;
                    CustomDialog.Builder dialog = new CustomDialog.Builder(context);
                    dialog.setTitle("提示");
                    dialog.setMessage("您确定要删除标签么");
                    dialog.setPositiveButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    });
                    dialog.setNegativeButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                            //长按删除
                            PictureTagLayout.this.removeView(touchView);
                        }
                    });
                    dialog.create().show();
//                  removeView(touchView);
                }
            }

        break;
        case MotionEvent.ACTION_UP:
            //此处是为了加入长按事件
            if(isLongClickModule){
                isLongClickModule = false;
                isLongClicking = false;
            }
            xUp = event.getX();
            Log.v("OnTouchListener", "Up");
            //按下和松开绝对值差当大于20时滑动,否则不显示
            if ((xUp - xDown) > 20)
            {
                //添加要处理的内容
            }
            else if((xUp - xDown ) < -20)
            {
                //添加要处理的内容
            }
            else if( 0 == (xDown - xUp))
            {
                int viewWidth = v.getWidth();
                if( xDown < viewWidth/3 )
                {
                    //靠左点击
                }
                else if(xDown > viewWidth/3 && xDown < viewWidth * 2 /3)
                {
                    //中间点击
                }
                else
                {
                    //靠右点击
                }
            }
            endX = (int) event.getX();
            endY = (int) event.getY();
            //如果挪动的范围很小,则判定为单击   单击换背景图片
            if(touchView!=null&& Math.abs(endX - startX)<CLICKRANGE&& Math.abs(endY - startY)<CLICKRANGE){
                clickView = touchView;
                if(hasView(endX,endY)){//如果点击位置已经有了
                    if ("L".equals(((PictureTagView)touchView).getDirection())){
                        Log.i("----direct---L",((PictureTagView)touchView).getDirection());
                        ((PictureTagView)touchView).directionChange(PictureTagView.Direction.Right);
                    }else if ("R".equals(((PictureTagView)touchView).getDirection())){
                        Log.i("----direct---R",((PictureTagView)touchView).getDirection());
                        ((PictureTagView)touchView).directionChange(PictureTagView.Direction.Left);
                    Log.i("---direct----",((PictureTagView)touchView).getDirection());
                    }
                } else {
                    showPopup();
                }
            }
//          touchView = null;
            break;

        }
        return true;
    }
    public void showPopup(){
        Intent intent=new Intent(context, ChooseBrandActivity.class);
        ((Activity)context).startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){

        }
    }
    /*
* ChooseBrandActivity中选择完品牌、位置、推荐、活动bi标签 用eventbus 发送到Sign_T_Activity中 然后发送到Sign_T_Activity中调用addData 把值传过来
* */
    public void addData(String brandId, String name, String type){
        if(hasView(startX,startY)){//有view 就不添加到集合里
            startTouchViewLeft = touchView.getLeft();
            startTouchViewTop = touchView.getTop();

        } else {
            if (!StringUtils.isEmptyString(name)){
                addItem(startX, startY,name,brandId,toWhere,type);
                //完成的时候  将标签信息对象 返给SignActivity
            }

        }
    }

    private void addItem(int x, int y, String share, String brandId, int toWhere, String type){
        View view = null;
        LayoutParams params=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        if(x>getWidth()*0.5){//Right是指 点在右边
            //第一次点击添加标签是  PictureTagView.Direction.Measure 让TagView自己测量方向   toWhere长按标签 向左滑动 还是向右
            view = new PictureTagView(getContext(), PictureTagView.Direction.Right,share,type);
            view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
            int w = MeasureSpec.makeMeasureSpec(0,
                    MeasureSpec.UNSPECIFIED);
            int h = View.MeasureSpec.makeMeasureSpec(0,
                    View.MeasureSpec.UNSPECIFIED);
            view.measure(w, h);
            height = view.getMeasuredHeight();
            width = view.getMeasuredWidth();
            //标签在右面 点击位置 x-标签宽度   右边的标签并不是以圆点开始的  而是以左边的wei
            params.leftMargin = x -width+10;
            ((PictureTagView)view).addText(share);
            if (brandId!=null){
                if (!"0".equals(brandId)){//品牌id 默认为int 类型的  默认值为0  如果为0 证明是自定义的品牌  就不给品牌id 赋值
                ((PictureTagView)view).addBrandId(brandId+"");
                }
            }
            params.topMargin = y-height/2;
        }else{
            params.leftMargin = x-10;
            view = new PictureTagView(getContext(), PictureTagView.Direction.Left,share,type);
            view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
            int w = MeasureSpec.makeMeasureSpec(0,
                    MeasureSpec.UNSPECIFIED);
            int h = View.MeasureSpec.makeMeasureSpec(0,
                    View.MeasureSpec.UNSPECIFIED);
            view.measure(w, h);
            height = view.getMeasuredHeight();
            width = view.getMeasuredWidth();
            ((PictureTagView)view).addText(share);
            if (brandId!=null){
                if ("0".equals(brandId)){//品牌id 默认为int 类型的  默认值为0  如果为0 证明是自定义的品牌  就不给品牌id 赋值
                    ((PictureTagView)view).addBrandId(brandId+"");
                }
            }
        params.topMargin = y-height/2;
        }
        //上下位置在视图内
        if(params.topMargin<=0){
            params.topMargin =0;
        } else if((params.topMargin+height)>getHeight()){
            params.topMargin = getHeight() -height;
        }
        if(params.leftMargin<=0){
            params.leftMargin=0;
        }
        if (params.rightMargin>=getWidth()){
            params.rightMargin=getWidth();
        }
        this.addView(view, params);
    }
    private void moveView(int x,int y){
        if(touchView == null) return;
        LayoutParams params=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.leftMargin = x - startX + startTouchViewLeft;
        params.topMargin = y - startY + startTouchViewTop;
        //限制子控件移动必须在视图范围内
        if(params.leftMargin<0||(params.leftMargin+touchView.getWidth())>getWidth()){
            params.leftMargin = touchView.getLeft();
        }
        if(params.topMargin<0||(params.topMargin+touchView.getHeight())>getHeight()){
            params.topMargin = touchView.getTop();
        }
        touchView.setLayoutParams(params);
    }

    private boolean hasView(int x,int y){
        //循环获取子view,判断xy是否在子view上,即判断是否按住了子view
        for(int index = 0; index < this.getChildCount(); index ++){
            View view = this.getChildAt(index);
            int left = (int) view.getX();
            int top = (int) view.getY();
            int right = view.getRight();
            int bottom = view.getBottom();
            ((PictureTagView)view).getShare();
            Rect rect = new Rect(left, top, right, bottom);
            boolean contains = rect.contains(x, y);
            //如果是与子view重叠则返回真,表示已经有了view不需要添加新view了
            if(contains){
                touchView = view;
                touchView.bringToFront();
                return true;
            }
        }
        touchView = null;
        return false;
    }
    /* 判断是否有长按动作发生
* @param lastX 按下时X坐标
* @param lastY 按下时Y坐标
* @param thisX 移动时X坐标
* @param thisY 移动时Y坐标
* @param lastDownTime 按下时间
* @param thisEventTime 移动时间
* @param longPressTime 判断长按时间的阀值
*/
    private boolean isLongPressed(float lastX,float lastY,
                                  float thisX,float thisY,
                                  long lastDownTime,long thisEventTime,
                                  long longPressTime){
        float offsetX = Math.abs(thisX - lastX);
        float offsetY = Math.abs(thisY - lastY);
        long intervalTime = thisEventTime - lastDownTime;
        if(offsetX <= 10 && offsetY <= 10 && intervalTime >= longPressTime){
            return true;
        }
        return false;
    }
}

接下来就是自定义标签PictureTagView

/*
*
* 带左右方向
* */
public class PictureTagView extends RelativeLayout implements OnEditorActionListener {

    private Context context;
    private TextView tvPictureTagLabel;
    private TextView etPictureTagLabel;
    private View loTag;
    private View view;
    private ImageView iv_circle_r;
    private ImageView iv_circle_l;
    private TextView tv_direction;
    private TextView tv_type;


    public enum Direction {Left, Right,Measure}

    private Direction direction;
    private InputMethodManager imm;
    private static final int ViewWidth = 80;
    private static final int ViewHeight = 50;
    private String share;
    private String type;//标签类型
    private boolean isMesure;//是否让其自动测量左右
    private int toWhere;//向右滑动为1 向左滑动为2

    public PictureTagView(Context context) {
        super(context);

    }

    public PictureTagView(Context context, Direction direction, String share, String type) {
        super(context);
        this.context = context;
        this.direction = direction;
        this.share=share;
        this.type=type;
        initViews();
        init();
        initEvents();
    }
    public void addText(String text){
        tvPictureTagLabel.setText(text);
    }
    /*
    * 设置移动标签时 往哪个方向滑动
    * */
    public void setToWhere(int ee){
        //在PictureTagLayout 中  setToWhere  将滑动方向传回来
        toWhere=ee;
    }
    public void addBrandId(String brandId){
        etPictureTagLabel.setText(brandId);
    }
    /**
     * 初始化视图
     **/
    protected void initViews() {
        view= LayoutInflater.from(context).inflate(R.layout.picturetagview, this, true);
        tvPictureTagLabel = (TextView) view.findViewById(R.id.tvPictureTagLabel);
        etPictureTagLabel = (TextView) view.findViewById(R.id.etPictureTagLabel);
        tv_direction = (TextView) view.findViewById(R.id.tv_direction);
        tv_type = (TextView) view.findViewById(R.id.tv_type);
        iv_circle_l = (ImageView) view.findViewById(R.id.iv_circle_l);
        iv_circle_r = (ImageView) view.findViewById(R.id.iv_circle_r);
        tvPictureTagLabel.setText(share);
        loTag = findViewById(R.id.loTag);
        tv_type.setText(type);
        if (Direction.Left.equals(direction)){

            iv_circle_l.setVisibility(View.VISIBLE);
            iv_circle_r.setVisibility(View.GONE);
            if ("SITE".equals(type)){
                iv_circle_l.setBackgroundResource(R.drawable.iv_loc_tag);
            }else{
                iv_circle_l.setBackgroundResource(R.drawable.img_point);
            }
            //加载动画
            Animation hyperspaceJumpAnimation =
                    AnimationUtils.loadAnimation(context, R.anim.circle);
//                //使用ImageView显示动画
            iv_circle_l.startAnimation(hyperspaceJumpAnimation);
            iv_circle_r.clearAnimation();
            tv_direction.setText("L");
            loTag.setBackgroundResource(R.drawable.bg_picturetagview_tagview_left);
        }else if (Direction.Right.equals(direction)){

            iv_circle_r.setVisibility(View.VISIBLE);
            iv_circle_l.setVisibility(View.GONE);
            if ("SITE".equals(type)){
                iv_circle_r.setBackgroundResource(R.drawable.iv_loc_tag);
            }else{
                iv_circle_r.setBackgroundResource(R.drawable.img_point);
            }
            //加载动画
            Animation hyperspaceJumpAnimation1 =
                    AnimationUtils.loadAnimation(context, R.anim.circle);
//                //使用ImageView显示动画
            iv_circle_r.startAnimation(hyperspaceJumpAnimation1);
            iv_circle_l.clearAnimation();
            tv_direction.setText("R");
            loTag.setBackgroundResource(R.drawable.bg_picturetagview_tagview_right);
        }
    }

    /**
     * 初始化
     **/
    protected void init() {
        imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
//        directionChange(direction);
    }
    public String getShare(){
        return tvPictureTagLabel.getText().toString();
    }
    public String getBrandId(){
        return etPictureTagLabel.getText().toString();
    }
    /*
    * tv_direction设置 标签的方向 L R   然后在获取标签时 直接调用getDirection 获取标签的方向
    * return  标签的方向
    * */
    public String getType(){
        return tv_type.getText().toString();
    }
    /*
   * tv_direction设置 标签的方向 L R   然后在获取标签时 直接调用getDirection 获取标签的方向
   * return  标签的方向
   * */
    public String getDirection(){
        return tv_direction.getText().toString();
    }
    /**
     * 初始化事件
     **/
    protected void initEvents() {
        etPictureTagLabel.setOnEditorActionListener(this);
    }


    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        return true;
    }



    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);


    }

    public void directionChange(Direction direction) {
        switch (direction) {
            case Left:
                iv_circle_l.setVisibility(View.VISIBLE);
                iv_circle_r.setVisibility(View.GONE);
                if ("SITE".equals(type)){
                    iv_circle_l.setBackgroundResource(R.drawable.iv_loc_tag);
                }else{
                    iv_circle_l.setBackgroundResource(R.drawable.img_point);
                }
                //加载动画
                Animation hyperspaceJumpAnimation =
                        AnimationUtils.loadAnimation(context, R.anim.circle);
                //使用ImageView显示动画
                iv_circle_l.startAnimation(hyperspaceJumpAnimation);
                iv_circle_r.clearAnimation();

                    //将标签的方向赋值给tv_direction  然后在getDirection方法中返回 便于Sign_T_Activity里调用
                    tv_direction.setText("L");
                    loTag.setBackgroundResource(R.drawable.bg_picturetagview_tagview_left);
                break;
            case Right:
                iv_circle_r.setVisibility(View.VISIBLE);
                iv_circle_l.setVisibility(View.GONE);
                if ("SITE".equals(type)){
                    iv_circle_r.setBackgroundResource(R.drawable.iv_loc_tag);
                }else{
                    iv_circle_r.setBackgroundResource(R.drawable.img_point);
                }
                //加载动画
                Animation hyperspaceJumpAnimation1 =
                        AnimationUtils.loadAnimation(context, R.anim.circle);
                //使用ImageView显示动画
                iv_circle_r.startAnimation(hyperspaceJumpAnimation1);
                iv_circle_l.clearAnimation();
                    tv_direction.setText("R");
                    loTag.setBackgroundResource(R.drawable.bg_picturetagview_tagview_right);
                break;
        }
    }
    public static int getViewWidth(){
        return ViewWidth;
    }
    public static int getViewHeight(){
        return ViewHeight;
    }
}

picturetagview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal" >
    <ImageView
        android:id="@+id/iv_circle_l"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        />
    <LinearLayout
        android:id="@+id/loTag"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:gravity="center_vertical"
        android:background="@drawable/bg_picturetagview_tagview_left" >
        <TextView
            android:id="@+id/tvPictureTagLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:gravity="center_vertical"
            android:layout_gravity="center_vertical"
            android:hint=""
            android:singleLine="true"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/etPictureTagLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:gravity="center_vertical"
            android:layout_gravity="center_vertical"
            android:hint=""
            android:imeOptions="actionDone"
            android:singleLine="true"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:textSize="10dp"
            android:visibility="gone" />
        <TextView
            android:id="@+id/tv_direction"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:gravity="center_vertical"
            android:layout_gravity="center_vertical"
            android:hint=""
            android:imeOptions="actionDone"
            android:maxLength="15"
            android:singleLine="true"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:textSize="10dp"
            android:visibility="gone" />
        <TextView
            android:id="@+id/tv_type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:gravity="center_vertical"
            android:layout_gravity="center_vertical"
            android:hint=""
            android:imeOptions="actionDone"
            android:maxLength="15"
            android:singleLine="true"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:textSize="10dp"
            android:visibility="gone" />
    </LinearLayout>
    <ImageView
        android:id="@+id/iv_circle_r"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        />
</LinearLayout>

ChooseBrandActivity标签列表类

/**
 * ---选择标签
 * Created by lzq 2017/6/28.
 */
public class ChooseBrandActivity extends Activity implements View.OnClickListener {

    private CustomDialogLoading.Builder builder;
    private CustomDialogLoading mDialog;

    private Context context;
    private String edit;

    private ArrayList<AttentionBrand> blist=new ArrayList<>();
    private MyListView lv_local_tag;//位置标签
    private MyListView lv_recom_tag;//推荐标签
    private RecomendLabelAdapter recommendAdapter;

    public List<RecordBean> recommendList;
    private ArrayList<RecordBean> localList;
    private RecomendLabelAdapter localAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_brand);
        context=this;
        builder = new CustomDialogLoading.Builder(this, "");
        mDialog = builder.create();
        initView();
        setListener();
    }


    private void initView() {
        lv_local_tag = (MyListView) findViewById(R.id.lv_local_tag);//位置
        lv_recom_tag = (MyListView) findViewById(R.id.lv_recom_tag);//推荐
        localList=new ArrayList<RecordBean>();
        RecordBean bean1=new RecordBean("SITE","北京饭桶天下");
        RecordBean bean2=new RecordBean("SITE","苏州街");
        RecordBean bean3=new RecordBean("SITE","中关村");
        RecordBean bean4=new RecordBean("SITE","国泰航空");
        RecordBean bean5=new RecordBean("SITE","银科大厦");
        RecordBean bean6=new RecordBean("SITE","中湾国际");
        localList.add(bean1);
        localList.add(bean2);
        localList.add(bean3);
        localList.add(bean4);
        localList.add(bean5);
        localList.add(bean6);
        recommendList=new ArrayList<RecordBean>();
        RecordBean bean11=new RecordBean("NORMAL","大约在冬季");
        RecordBean bean22=new RecordBean("NORMAL","你最美");
        RecordBean bean33=new RecordBean("NORMAL","帅到没朋友");
        RecordBean bean44=new RecordBean("NORMAL","我最帅");
        RecordBean bean55=new RecordBean("NORMAL","哇咔咔");
        RecordBean bean66=new RecordBean("NORMAL","互相伤害啊");
        recommendList.add(bean11);
        recommendList.add(bean22);
        recommendList.add(bean33);
        recommendList.add(bean44);
        recommendList.add(bean55);
        recommendList.add(bean66);
        //本地的位置
        lv_local_tag.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                EventBus.getDefault().post(new LocTagEvent(localList.get(i).getType(),localList.get(i).getName()));
                Toast.makeText(context,localList.get(i).getName(),Toast.LENGTH_SHORT).show();
                finish();
            }
        });
        localAdapter = new RecomendLabelAdapter(context, localList);
        lv_local_tag.setAdapter(localAdapter);
        //推荐的位置
        lv_recom_tag.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                EventBus.getDefault().post(new LocTagEvent(recommendList.get(i).getType(),recommendList.get(i).getName()));
                Toast.makeText(context,recommendList.get(i).getName(),Toast.LENGTH_SHORT).show();
                finish();
            }
        });
        recommendAdapter = new RecomendLabelAdapter(context, recommendList);
        lv_recom_tag.setAdapter(recommendAdapter);
        lv_recom_tag.setDividerHeight(28);
    }

    private void setListener() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        }

    }
    @Subscribe(threadMode = ThreadMode.MAIN) //注册一个在后台线程执行的方法,用于接收事件
    public void onUserEvent(CustomEditTextDialog.Builder.EventClass event) {//参数必须是ClassEvent类型, 否则不会调用此方法
// Toast.makeText(MainActivity.this,event.data,Toast.LENGTH_SHORT).show();
        edit=event.edit;
        Log.i("edit--", edit);
    }



    //在任意地方,注册事件类
    public static class ClassEvent{
        public AttentionBrand data;
        ClassEvent( AttentionBrand data){
            this.data=data;
        };
    }
    @Override
    public void onResume() {
        super.onResume();
    }
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值