1.先上图
2.代码
package com.zhuochi.hydream.bathhousekeeper.view.customview;
import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.zhuochi.hydream.bathhousekeeper.R;
import com.zhuochi.hydream.bathhousekeeper.utils.ToastUtils;
import butterknife.BindView;
import butterknife.OnClick;
/**
* 筛选自定义view
* @author Cuixc
* @date on 2018/8/15
*/
public class HeightSelectView extends LinearLayout {
TextView tvMultistageQuery;
TextView tvTitleQuery;
TextView tvSelect;
TextView tvStartTime;
@BindView(R.id.view)
View view;
TextView tvEndTime;
TextView tvSelected;
private Context mContext;
private SelcetCallBack mCallBack;
public HeightSelectView(Context context) {
super(context);
init(context);
}
public HeightSelectView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public HeightSelectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public void addCallBack(SelcetCallBack callBack){
mCallBack=callBack;
}
private void init(Context context) {
mContext = context;
View view = LayoutInflater.from(context).inflate(R.layout.view_head_select, this, true);
tvSelect = (TextView) view.findViewById(R.id.edit_select);
tvMultistageQuery = (TextView) view.findViewById(R.id.tv_multistageQuery);
tvTitleQuery = (TextView) view.findViewById(R.id.tv_titleQuery);
tvStartTime = (TextView) view.findViewById(R.id.tv_startTime);
tvEndTime = (TextView) view.findViewById(R.id.tv_endTime);
tvSelected = (TextView) view.findViewById(R.id.tv_select);
}
@OnClick({R.id.tv_select, R.id.edit_select})
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv_select://点击查询
if (TextUtils.isEmpty(tvSelect.getText().toString())) {
ToastUtils.show("校区查询栏不可为空!");
return;
}
if (TextUtils.isEmpty(tvStartTime.getText().toString()) || TextUtils.isEmpty(tvEndTime.getText())) {
ToastUtils.show("时间查询栏不可为空!");
return;
}
mCallBack.CallBackSelect(1,"","");
break;
case R.id.edit_select://跳转学校
break;
}
}
// 选择回调
public interface SelcetCallBack {
//学校id,开始时间, 结束时间
void CallBackSelect(int schoolID, String StartTime, String EndTime);
}
}
3.布局文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:background="@color/white" android:padding="@dimen/dp15" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_multistageQuery" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/dp14" android:textColor="@color/black333" android:text="@string/multistage_query"/> <TextView android:layout_below="@+id/tv_multistageQuery" android:id="@+id/tv_titleQuery" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/dp15" android:textSize="@dimen/dp14" android:textColor="@color/black333" android:text="@string/title_query"/> <TextView android:id="@+id/edit_select" android:layout_toRightOf="@id/tv_multistageQuery" android:layout_marginLeft="@dimen/dp13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="3dp" android:hint="查询:学校校区" android:paddingLeft="@dimen/dp10" android:textSize="12dp" android:background="@mipmap/icon_searchbox_one"/> <TextView android:id="@+id/tv_startTime" android:gravity="center" android:layout_below="@id/edit_select" android:layout_toRightOf="@+id/tv_titleQuery" android:layout_marginTop="5dp" android:layout_marginLeft="@dimen/dp15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/icon_searchbox_two"/> <View android:id="@+id/view" android:layout_below="@id/edit_select" android:layout_toRightOf="@+id/tv_startTime" android:layout_marginTop="@dimen/dp15" android:background="@color/theme_color" android:layout_width="20dp" android:layout_marginLeft="3dp" android:layout_marginRight="3dp" android:layout_height="1dp"/> <TextView android:id="@+id/tv_endTime" android:gravity="center" android:layout_below="@id/edit_select" android:layout_toRightOf="@+id/view" android:layout_marginTop="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/icon_searchbox_two"/> <TextView android:id="@+id/tv_select" android:layout_alignParentRight="true" android:layout_marginTop="@dimen/dp10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/icon_search"/> </RelativeLayout>