Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建可变数量的按钮,并且我希望它们相邻(我不能使用ListView),所以我知道我必须以Button某种方式给 a 充气。我的问题是如何Button为每个创建的按钮充气,如何创建一个监听器?
ListView
Button
谢谢
我对您的要求有点困惑,但是要在您的活动中为按钮充气,请致电:
Button myButton = (Button)findViewById(R.id.layout_xml_name);
然后,添加一个监听器:
myButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Your buttons desired actions } });