button,怎么使每次点击都可以把数组记录下来
1个回答
展开全部
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnLongClickListener {
private Button[] city_button_array = new Button[10];
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// button[] 初始化 自己解决
for (int i = 0; i < city_button_array.length; i++) {
city_button_array[i].setOnLongClickListener(this);
}
}
@Override
public boolean onLongClick(View view) {
int id = view.getId();
for (int i = 0; i < city_button_array.length; i++) {
if (city_button_array[i].getId() == id) {
city_button_array[i].setVisibility(View.GONE);
city_button_array[i].setText("");
}
}
return false;
}
}
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnLongClickListener {
private Button[] city_button_array = new Button[10];
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// button[] 初始化 自己解决
for (int i = 0; i < city_button_array.length; i++) {
city_button_array[i].setOnLongClickListener(this);
}
}
@Override
public boolean onLongClick(View view) {
int id = view.getId();
for (int i = 0; i < city_button_array.length; i++) {
if (city_button_array[i].getId() == id) {
city_button_array[i].setVisibility(View.GONE);
city_button_array[i].setText("");
}
}
return false;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询