안녕하세요.
ExpandableList 를 이용해서 메뉴를 구성하는데..
ExpandableList 안에 이비지 버튼을 하나 넣고 해당 버튼은 다른 이벤트를 주고 싶습니다.
코드는 아래와 같습니다.
mList = (ExpandableListView) findViewById(R.id.brand_expandableListView);
ExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this,
BrandData,
R.layout.brand_name_list_expand_group,
new String[] {"Brand_name"},
new int[] {R.id.expand_group_brand_text},
valBrandData,
R.layout.brand_name_list_expand_child,
new String[] {"Brand_val"},
new int[] {R.id.expand_child_brand_text}
);
mList.setAdapter(adapter);
mList.setGroupIndicator(null);
mList.setAddStatesFromChildren(true);
mList.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
final int g = groupPosition;
final int c = childPosition;
scrap_brandNamestat = true;
ImageView brandNameScrap = (ImageView) v.findViewById(R.id.brandNameScrapBtn);
brandNameScrap.setOnClickListener(new OnClickListener() {
public void onClick(View v) { <<--- 이부분에 버튼 클릭 이벤트를 두었습니다.
// TODO Auto-generated method stub
showLog(findvalBrand[g][c] + "-" + findcodeBrand[g][c]);
scrap_brandNamestat = false;
((ImageView)v).setImageResource(R.drawable.star_on);
}
});
if (scrap_brandNamestat) { //page move
showLog("PAGE MOVE : " + findvalBrand[g][c] + "-" + findcodeBrand[g][c]);
}
return false;
}
});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="@drawable/brand_name_list"
android:orientation="horizontal"
android:paddingLeft="10px" >
<ImageView
android:id="@+id/brandNameScrapBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/star_off" />
<TextView
android:id="@+id/expand_child_brand_text"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textColor="@color/brand_name_list_textcolor"
android:textSize="13dp" android:layout_width="fill_parent" android:layout_marginLeft="10dp"/>
</LinearLayout>
</RelativeLayout>
위와같이 코딩하여 결과를 보게되면..
해당 이미지를 누르게 되면 최초 한번은 ExpandableList 의 컬럼이 클릭이 됩니다.
그 이후 해당 이미지를 누르면 그때 이벤트가 발생하게 되는데.. 포커스가 이동한 후 이미지 버튼 이벤트가 발생한다고 생각했는데.
다른 컬럼을 모두 클릭후 해당이미지를 클릭하면 되더라고요.. 결론은 최초 한번은 컬럼이 클릭된다는.. ㅠㅠ
위와같이 코딩하는게 아닌가요? 다른 방법이 있을까요??




혹시 리스너 return false 때문일수도 있어요. return true으로 바꿔서 해보세요.