本文介绍了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:隐藏其他活动的按钮
发布评论