import android.R.interpolator;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Cusor_TypeAdapter extends LinearLayout {
//三种构造方法都实现
public Cusor_TypeAdapter(Context context) {
super(context);
initView(context);
}
public Cusor_TypeAdapter(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public Cusor_TypeAdapter(Context context, AttributeSet attrs, int count) {
super(context, attrs, count);
initView(context);
}
View aView;
Button Left, Right;
TextView center;
private void initView(final Context context) {
aView = LayoutInflater.from(context).inflate(
R.layout.cusor_typeadapter, null);
this.addView(aView);
Left = (Button) aView.findViewById(R.id.button2);
center = (TextView) aView.findViewById(R.id.button1);
Right = (Button) aView.findViewById(R.id.button3);
/**
*
* 监听OnClickListener通过接口返回
*/
Left.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (myOnItem != null) {
myOnItem.LeftOnClick();
}
}
});
Right.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (myOnItem != null) {
myOnItem.RightOnClick();
}
}
});
}
/**
* TextView背景色
*
*/
public void setTextViewBackGround(int mColor){
center.setBackgroundColor(mColor);
}
/**
* TextView字體顏色
*
*/
public void setTextSizeColor(int mColor){
center.setTextColor(mColor);
}
/**
*
* 字
*
* @param text
*/
public void setText(String[] text) {
Left.setText(text[0]);
center.setText(text[1]);
Right.setText(text[2]);
}
/**
*
* 字体大小
*
* @param ma
*/
public void setTextSize(int[] ma) {
Left.setTextSize(ma[0]);
center.setTextSize(ma[1]);
Right.setTextSize(ma[2]);
}
MyOnItemListener myOnItem;
/**
*
* 接口初始化
*
* @param myOnItem
* 接口对象
* @param mAdapter
* 类对象
*/
public void setLeftOnClick(MyOnItemListener myOnItem,
Cusor_TypeAdapter mAdapter) {
this.myOnItem = myOnItem;
}
/**
*
* 该接口用于通信
*
* @author Administrator
*
*/
public interface MyOnItemListener {
/**
*
* 左边按钮点击
*/
void LeftOnClick();
/**
*
* 右边按钮点击
*/
void RightOnClick();
}
}
cusor_typeadapter.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>