public class Custom extends LinearLayout {
ToView toView;
public Button btn_id;
public Button creatbitmap_id, suchbut;
public Button clbitmap_id;
public EditText editText;
public Custom ( Context context) {
super ( context) ;
}
public Custom ( Context context, @Nullable AttributeSet attrs) {
super ( context, attrs) ;
View view = LayoutInflater. from ( context) . inflate ( R. layout. custmview_layout, this ) ;
btn_id = view. findViewById ( R. id. but_id) ;
creatbitmap_id = view. findViewById ( R. id. creatbitmap_id) ;
clbitmap_id = view. findViewById ( R. id. clbitmap_id) ;
editText = view. findViewById ( R. id. edt_id) ;
suchbut = view. findViewById ( R. id. sech_id) ;
suchbut. setOnClickListener ( new OnClickListener ( ) {
@Override
public void onClick ( View v) {
String comt = editText. getText ( ) . toString ( ) ;
toView. suechCont ( comt) ;
}
} ) ;
}
public Custom ( Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super ( context, attrs, defStyleAttr) ;
}
public void setToView ( ToView toView) {
this . toView = toView;
}
public interface ToView {
public void suechCont ( String cont) ;
}
}
< LinearLayout xmlns: android= " http://schemas.android.com/apk/res/android"
android: orientation= " vertical" android: layout_width= " match_parent"
android: layout_height= " match_parent" >
< LinearLayout
android: layout_width= " match_parent"
android: layout_height= " match_parent"
android: orientation= " horizontal"
android: gravity= " center"
>
< Button
android: id= " @+id/but_id"
android: layout_width= " wrap_content"
android: layout_height= " wrap_content"
android: text= " 扫描二维码" />
< EditText
android: id= " @+id/edt_id"
android: layout_width= " 200dp"
android: layout_height= " wrap_content"
android: layout_marginLeft= " 10dp" />
< Button
android: id= " @+id/sech_id"
android: layout_width= " 30dp"
android: layout_height= " wrap_content"
android: layout_marginLeft= " 10dp"
android: text= " 搜索" />
< Button
android: id= " @+id/creatbitmap_id"
android: layout_width= " wrap_content"
android: layout_height= " wrap_content"
android: text= " 生成" />
< ImageView
android: id= " @+id/imag_id"
android: layout_width= " wrap_content"
android: layout_height= " wrap_content"
/>
< Button
android: text= " 解析"
android: id= " @+id/clbitmap_id"
android: layout_width= " wrap_content"
android: layout_height= " wrap_content" />
</ LinearLayout>
</ LinearLayout>