Sample android custom control and custom callback function steps
- 2020-05-24 06:05:43
- OfStack
Steps for custom controls:
How the 1 View works
2. Write the View class
Add attributes to the View class
4 draw the screen
Respond to user messages
6. Custom callback function
java code
private class MyText extends LinearLayout {
private TextView text1;
/*
* private String text;
*
* public String getText() { return text; }
*
* public void setText(String text) { this.text = text; }
*/
public MyText(Context context) {
super(context);
// TODO Auto-generated constructor stub
LayoutInflater inflate = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = inflate.inflate(R.layout.tabhost_item, this, true);
text1 = (TextView) view.findViewById(R.id.tabhost_tv);
}
public void setTextViewText(String tabhost_name) {
text1.setText(tabhost_name);
}
/*
* @Override protected void onDraw(Canvas canvas) { // TODO
* Auto-generated method stub super.onDraw(canvas); Paint p = new
* Paint(); p.setColor(Color.WHITE); p.setTextSize(10);
* canvas.drawText(text, 25, 25, p); }
*/
}
xml code
<?xml version="1.0" encoding="utf-8"?>
<!-- GMapTabActivity Custom control in MyText Since the layout -->
<TextView
android:id="@+id/tabhost_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>