app
package dongyushan.bwie.com.lianxi.app; import com.facebook.drawee.backends.pipeline.Fresco; public class Application extends android.app.Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }
layout
package dongyushan.bwie.com.lianxi.bean; import android.content.Context; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import dongyushan.bwie.com.lianxi.R; public class NumberLayout extends LinearLayout implements View.OnClickListener { private TextView textLost; private TextView textShow; private TextView textAdd; public NumberLayout(Context context, @Nullable AttributeSet attrs) { super(context, attrs); View view = inflate(context, R.layout.number_layout, this); textLost = view.findViewById(R.id.text_lost); textShow = view.findViewById(R.id.text_show); textAdd = view.findViewById(R.id.text_add); textLost.setOnClickListener(this); textAdd.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.text_lost: int lostNum = Integer.parseInt(getTextShow()); if (lostNum > 1) { lostNum--; setTextShow("" + lostNum); if(listener != null){ listener.changeTakeNum(getTextShow()); } } else { Toast.makeText(getContext(), "最小数量为1", Toast.LENGTH_SHORT).show(); } break; case R.id.text_add: int addNum = Integer.parseInt(getTextShow()); addNum++; setTextShow("" + addNum); if(listener != null){ listener.changeTakeNum(getTextShow()); } break; } } public String getTextShow() { return textShow.getText().toString(); } public void setTextShow(String num) { textShow.setText(num); } // 用于回调的接口 public OnChangeNumListener listener; public interface OnChangeNumListener { void changeTakeNum(String str); } public void setListener(OnChangeNumListener listener) { this.listener = listener; } }