public class MainActivity extends Activity implements View.OnClickListener {
private Button button;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
tv = (TextView)findViewById(R.id.textView);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int vi = tv.getVisibility();
if(vi !=0)
{
tv.setVisibility(0);
}
else
tv.setVisibility(4);
}
}
public class MainActivity extends Activity{
private Button button;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
tv = (TextView)findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int vi = tv.getVisibility();
if(vi !=0)
{
tv.setVisibility(0);
}
else
tv.setVisibility(4);
}
})
}
}前者是外部类监听, 后者是匿名内部类嘛?
添加回答
举报
0/150
提交
取消