我还是一个初学者,试图制作一个简单的应用程序,在android studio中使用java调用宾果游戏数字。一旦被叫,我就无法删除号码了。我正在尝试将数组列表公开并可以通过我的按钮方法访问,但我得到“无法解析符号'球'”。我已经尝试将数组列表放在<div class="isotope-item size3 col-lg-4 col-md-4 col-sm-12 col-xs-12 white-coat-talent all">
<div class="pm-gallery-post-item-container" style="background-image:url(img/gallery/2nd-white-coat1.jpg);">
<div class="pm-gallery-post-item-info-container">
<div class="pm-gallery-item-excerpt">
<p>LPSA hosted a talent show “White Coat Talent”, showcasing the talents of pharmacy students from all over Lebanon at Saint Joseph University.</p>
<ul class="pm-gallery-item-btns">
<li><a class="fa fa-camera lightbox" data-rel="prettyPhoto[white-coat-talent]" href="img/gallery/white-coat-talent11.jpg"></a></li>
<li><a class="fa-bars" href="#"></a></li>
</ul>
</div>
</div>
<a class="pm-gallery-item-expander fa fa-plus" href="#"></a>
</div>
<div class="pm-gallery-item-title">
<p>White Coat Talent</p>
</div>
</div>
下面,但后来我告诉我需要声明最终的球。如果我这样做,我以后无法从数组列表中删除。我尝试了很多不同的东西,但我似乎无法得到它,任何建议都表示赞赏!
类MainActivity扩展了AppCompatActivity {
onCreate()
答案 0 :(得分:0)
一般来说,在android studio中不需要所谓的&#34; main&#34;在其他java程序中广泛使用的函数,因为它默认情况下没有相同的用法。但是,onCreate()
方法通常可以被称为类似于main
的用法。以下代码解决了您的问题:
public class MainActivity extends AppCompatActivity{
private ArrayList<String> ball;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
ball = new ArrayList<String>();
ball.add("B1");
ball.add("B2");
ball.add("B3");
ball.add("B4");
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Random r = new Random();
String call = ball.get(r.nextInt(ball.size()));
TextView text = (TextView) findViewById(R.id.result);
text.setText(call);
ball.remove(r);
}
});
}
}
我强烈建议您再次浏览android的基础知识,最好从Android Developers:Understand the Activity Lifecycle开始。
希望我帮忙,