我一直在玩ExpandableListView很多,我無法弄清楚爲按鈕添加按鈕偵聽器,這將是視圖中的孩子。我設法得到了一個按鈕偵聽器,它使用下面的getChildView(),但它似乎是所有按鈕的同一個偵聽器。Androids ExpandableListView - 在哪裏把按鈕監聽器是兒童的按鈕
最好的情況是,我可以在實例化ExpandableListAdapter類的類中實現按鈕偵聽器,而不必將實際的ExpandableListAdapter類中的偵聽器。在這一點上,我甚至不知道這是可能的
我一直在嘗試本教程/代碼:HERE
getChildView()
@Override
public View getChildView(int set_new, int child_position, boolean view, View view1, ViewGroup view_group1)
{
ChildHolder childHolder;
if (view1 == null)
{
view1 = LayoutInflater.from(info_context).inflate(R.layout.list_group_item_lv, null);
childHolder = new ChildHolder();
childHolder.section_btn = (Button)view1.findViewById(R.id.item_title);
view1.setTag(childHolder);
childHolder.section_btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(info_context, "button pushed", Toast.LENGTH_SHORT).show();
}
});
}else {
childHolder = (ChildHolder) view1.getTag();
}
childHolder.section_btn.setText(children_collection.get(set_new).GroupItemCollection.get(child_position).section);
Typeface tf = Typeface.createFromAsset(info_context.getAssets(), "fonts/AGENCYR.TTF");
childHolder.section_btn.setTypeface(tf);
return view1;
}
任何幫助將不勝感激。謝謝,我會站在旁邊。
非常感謝你和偉大的想法從實際的部件中獲取字符串,不知道爲什麼我沒有想到這一點。 – CommonKnowledge 2012-07-06 20:35:02