Android:隐藏其他活动的按钮

编程入门 行业动态 更新时间:2024-10-27 02:25:12
本文介绍了Android:隐藏其他活动的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有2个活动。最初,第一个活动中的按钮是不可见的。我想要的是,当我在第二个活动中单击一个按钮时,第一个活动中的按钮应该可见。

I have 2 activities. Initially the button in first activity is invisible. What I want is that when I click a button in the second activity then the button in my first activity should become visible.

这是我到目前为止的第二个活动代码。 / p>

This is my second activity code till now.

this.promodeimage.setOnClickListener(new OnClickListener() { public void onClick(View view) { ///What should i do in here } });

推荐答案

做一件事!这很容易..只需在您的第一个活动中将按钮设置为public static

public class Activity_One extends Activity { public static Button btnOne ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_one); btnOne = (Button) findViewById(R.id.btnOne); }

现在,您需要做的就是通过第二项活动访问它使用第一个活动的类名,即Activity_One.btnOne

Now all you need to do is that from Second Activity just access it using the class name of the first activity i.e Activity_One.btnOne

public class Activity_Two extends Activity { Button btnTwo ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_one); btnTwo = (Button) findViewById(R.id.btnTwo); btnTwo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Activity_One.btnOne.setVisibility(View.GONE); } }); }

让我知道这是否对您有用! :)

Let me know if this works for you ! :)

更多推荐

Android:隐藏其他活动的按钮

本文发布于:2023-11-27 10:36:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!