如何使模拟时钟不可见的,可见点击按钮,机器人 [英] how to make analog clock invisible and visible on click button android
本文介绍了如何使模拟时钟不可见的,可见点击按钮,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序的工作,并希望不可见的,可见模拟时钟当我点击按钮
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=#000000
机器人:方向=垂直>< AnalogClock
机器人:ID =@ + ID / AnalogClock
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心/><按钮
机器人:ID =@ + ID /节目
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=秀/><按钮
机器人:ID =@ + ID /隐藏
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=隐藏/>
这里是code,我使用,但它不工作
最后AnalogClock时钟=(AnalogClock)findViewById(R.id.AnalogClock);
按钮显示=(按钮)findViewById(R.id.show);
按钮隐藏=(按钮)findViewById(R.id.hide);
show.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){ clock.setVisibility(View.VISIBLE);
} });
hide.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){ clock.setVisibility(View.GONE);
} });
我想点击按钮,但没有行动,因此任何人知道如何使它工作请....
解决方案
AnalogClock时钟=(AnalogClock)V;
clock.setVisibility(View.GONE);
这是错误的,v是你的按钮,而不是时钟。你需要做的只是
clock.setVisibility(View.GONE);
修改
我测试过你的code和它的作品:
公共类MainActivity延伸活动{ @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main); 最后AnalogClock时钟=(AnalogClock)findViewById(R.id.AnalogClock);
按钮显示=(按钮)findViewById(R.id.show);
按钮隐藏=(按钮)findViewById(R.id.hide); show.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
clock.setVisibility(View.VISIBLE);
}
});
hide.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
clock.setVisibility(View.INVISIBLE);
}
});
} }
和布局:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=#000000
机器人:方向=垂直> < AnalogClock
机器人:ID =@ + ID / AnalogClock
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心/> <按钮
机器人:ID =@ + ID /节目
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=秀/> <按钮
机器人:ID =@ + ID /隐藏
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=隐藏/>< / LinearLayout中>
i working in app and want to invisible and visible the analog clock when i click on buttons
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/AnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show" />
<Button
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hide" />
here is the code that i used but its not working
final AnalogClock clock =(AnalogClock) findViewById(R.id.AnalogClock);
Button show= (Button) findViewById(R.id.show);
Button hide= (Button) findViewById(R.id.hide);
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clock.setVisibility(View.VISIBLE);
}
});
hide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clock.setVisibility(View.GONE);
}
});
i trying to click on buttons but there is no actions so any one know how to make it works please ....
解决方案
AnalogClock clock = (AnalogClock) v;
clock.setVisibility(View.GONE);
this is wrong, v is your button, not the clock. you need to just do
clock.setVisibility(View.GONE);
EDIT I've tested your code and it works:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final AnalogClock clock = (AnalogClock) findViewById(R.id.AnalogClock);
Button show = (Button) findViewById(R.id.show);
Button hide = (Button) findViewById(R.id.hide);
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clock.setVisibility(View.VISIBLE);
}
});
hide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clock.setVisibility(View.INVISIBLE);
}
});
}
}
And the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/AnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show" />
<Button
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hide" />
</LinearLayout>
这篇关于如何使模拟时钟不可见的,可见点击按钮,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文