我想要做的是有一个循环,并且每次循环我想
1)根据x是什么来更改TextView的文本 2)获取EditText的文本并将其设置为ArrayList
除非我单击一个按钮,否则循环不应该继续,这意味着程序在继续代码之前等待用户单击按钮,所有这些都在循环中。
我宁愿不使用线程因为过去的麻烦,所以如果还有其他方式我会欢迎它
答案 0 :(得分:0)
正如你在问题中所述
the loop should not continue unless I click a button, meaning that the program waits for the user to click a button before continuing the code, and all this is in a loop.
为什么不把你的代码放在onClickListener
中它会做同样的事情,而不是暂停执行没有意义的代码。
List editTextValue=new ArrayList();
button.setOnClickListener(){
textView.setText(x);
editTextValue.add(editText.getText());
}
在上面的代码片段中,它正在实现您想要实现的目标。只要按钮为textView's text
,它就会在editText value
中设置arraylist
和clicked
。
答案 1 :(得分:0)
循环是一个非常糟糕的主意有很多原因。特别是如果你只是在触摸或每次迭代后做事情。 Android的设计并非如此。正如其他人告诉你的那样,你需要通过一个事件来解决这个问题。您需要执行以下操作:
List list = new ArrayList();
int x = 0;
然后
button.setOnClickListener(){
textView.setText(x);
list.add(editText.getText());
x++;
}
很抱歉,如果我无法扩展我的答案,但我正在通电话。