应该是你代码写的有问题。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package test;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public
class
TestView extends LinearLayout implements OnClickListener
{
private
Button button;
private
TextView textView;
public
TestView(Context context)
{
super(context);
setupUI(context);
}
public
TestView(Context context, AttributeSet attrSet)
{
super(context, attrSet);
setupUI(context);
}
private
void
setupUI(Context context)
{
if
(button != null ||
this
.isInEditMode())
return
;
button =
new
Button(context);
button.setText(
"test"
);
addView(button);
textView =
new
TextView(context);
textView.setText(
"textview"
);
addView(textView);
button.setOnClickListener(
this
);
}
@Override
public
void
onClick(View v)
{
setVisibility(View.GONE);
}
}
|