我正在開發Android應用程序。如何在ExpandableListView中的組項中放置一個按鈕?
我怎麼能放一個按鈕,一組ExpandableListView的?
通過點擊按鈕,對話框將顯示,而不是打開或關閉該組。點擊按鈕外部,組應該正常打開和關閉。
的下面圖像示出了其中我想插入的按鈕。
http://img193.imageshack.us/img193/2060/expandablelistviewbutto.png
我正在開發Android應用程序。如何在ExpandableListView中的組項中放置一個按鈕?
我怎麼能放一個按鈕,一組ExpandableListView的?
通過點擊按鈕,對話框將顯示,而不是打開或關閉該組。點擊按鈕外部,組應該正常打開和關閉。
的下面圖像示出了其中我想插入的按鈕。
http://img193.imageshack.us/img193/2060/expandablelistviewbutto.png
我創造了我自己的ExpandableListView。我使用XML和類中的佈局來構建組件。
令人驚訝的是,這很容易做到。
這是容易得多比標準ExpandableListView理解,因爲我創建了一個類,併爲列表中的每個元素的佈局(在列表本身,組和項目)。沒有必要搞亂地圖列表,這在我看來會降低代碼的表現力和可讀性。
此外,該列表變得非常靈活和可定製。我可以在運行時輕鬆添加和刪除組和項目。現在我可以自由修改列表的外觀和內部組件。
我創建可以做同樣的標準和更多的ExpandableListView。只是不知道表現是否受損,但沒有注意到任何明顯的問題。
你是如何把按鈕,使其工作?我有這個問題,我不能拿出一個解決方案http://stackoverflow.com/questions/11205052/button-in-a-row-in-expandablelistview – noloman
您需要充氣包含一個按鈕自定義XML文件中的groupView,像這樣的(如inflate_xml_groupview.xml
):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayoutGroupView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ButtonOfMyExpandableListGroupView"
android:visibility="visible" />
</FrameLayout>
然後,你必須創建一個擴展BaseExpandableListAdapter定製ExpandableListAdapter並獲得按鈕在getGroupView()方法,像這樣:
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.inflate_xml_groupview, null);
holder = new ViewHolder();
holder.Button = (Button) convertView.findViewById(R.id.myButton);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.position = ListOfItems.get(groupPosition).getPosition();
Button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), "Button " + groupPosition + " is clicked !", Toast.LENGTH_SHORT).show();
// DO STUFF
}
});
}
希望這有助於。
Android ExpandableListView可以在Group或Child中有任何按鈕。
確保按鈕不可作爲焦點,像下面的適配器。
editButton.setFocusable(false);
這將有助於點擊集團和按鈕內部group.parent seperately
是的,這應該是答案。 –
在代碼中執行它非常重要,而不是XML。像魅力一樣工作,感謝分享。 –
對我來說同樣的問題。複選框與標題佈局..不擴大/摺疊。添加此行後如同魅力 –
是ü能尚未解決這個問題? – modabeckham