首页 > 代码库 > 组合组件

组合组件

package com.example.ceshi;

import android.app.Activity;
import android.content.Context;
import android.opengl.Visibility;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

public class TitleView extends FrameLayout {
    private View _view;
    private Button _back;
    private Button _right;
    private TextView _title;
    public TitleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        _view = LayoutInflater.from(context).inflate(R.layout.title, this);        
        _back = (Button)_view.findViewById(R.id.back);
        
        _right = (Button)_view.findViewById(R.id.right);
        _title = (TextView)_view.findViewById(R.id.title);
        
        _back.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                ((Activity)getContext()).finish();
            }
        });
        
    }
    
    public void setLeftButtonText(String str){
        _back.setText(str);
    }

    public void setTitleText(String str){
        _title.setText(str);
    }
    
    public void setRightButton(Boolean bool){
        bool = bool ? true:false;
        if(bool){
            _right.setVisibility(VISIBLE);
        }else{
            _right.setVisibility(GONE);
        }
        
    }
    
    public void setRightOnclick(OnClickListener onClickListener){
        _right.setOnClickListener(onClickListener);
    }
}