2012-04-06 66 views
0

我在android中创建了一个expandableListView,其中的子包含两个按钮。ActionListener在expandableListView

这些按钮的actionlisterner在另一个类中。我怎样才能让actionListeners在子视图中的按钮被点击后被调用?

这就是我试图做的:

public View getChildView(int groupPosition, int childPosition, 
    boolean isLastChild, View convertView, ViewGroup parent) { 

    if (convertView == null) { 
    LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    convertView = inflater.inflate(R.layout.childrow, null); 
    Button b1 = (Button) convertView.findViewById(R.id.button1); 
    Button b2 = (Button) convertView.findViewById(R.id.button2); 


    classWithListeners p = new ClassWithListeners(b1,b2); 

}

回答

0

有ClassWithListeners实现任何你想要的ActionListener监听(即onClickListener)

,然后做

ClassWithListeners p = new ClassWithListeners(b1,b2); 
b1.setOnClickListener(p); 
b2.setOnClickListener(p);