순서
1. class
2. xml
1. class
public class ActScrap extends ActBase {
private Context context;
private ExpandableListView expandableListView;
private AdapScrap scrapAdapter;
private ArrayList<String> groupList; // 1차 분류
private ArrayList<ArrayList<String>> childList; // 2차 분류
private ArrayList<String> childContentList; // 2차 분류 내용
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_scrap);
context = this;
expandableListView = (ExpandableListView) findViewById(R.id.expandable_listview);
groupList = new ArrayList<String>();
childList = new ArrayList<ArrayList<String>>();
childContentList = new ArrayList<String>();
setExpandableListViewListener();
for(int i = 0; i < 10; i++) {
groupList.add(i + " parentList");
childContentList.add(i + " childContent");
childList.add(childContentList);
}
scrapAdapter = new AdapScrap(context, groupList, childList);
expandableListView.setAdapter(scrapAdapter);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
// 확장리스트의 기본 화살표가 왼쪽에 있어 오른쪽으로 옮김
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
expandableListView.setIndicatorBounds(width - CommonUtils.getPixelFromDips(context, 50), width - CommonUtils.getPixelFromDips(context, 10));
} else {
expandableListView.setIndicatorBoundsRelative(width - CommonUtils.getPixelFromDips(context, 30), width - CommonUtils.getPixelFromDips(context, 1));
}
}
/**
* 확장리스트에 대한 클릭리스너 설정
*/
private void setExpandableListViewListener() {
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
CommonUtils.showShortToast(context, "Group id: " + id + " name: " + scrapAdapter.getGroup(groupPosition));
return false;
}
});
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
CommonUtils.showShortToast(context, "Child id: " + id + " name: " + scrapAdapter.getChild(groupPosition, childPosition));
return false;
}
});
}
}
2. xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="90dp" >
<Button
android:id="@+id/category_btn"
android:layout_width="match_parent"
android:layout_height="51dp"
android:background="@drawable/selector_tips_category_btn" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="51dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="17dp"
android:src="@drawable/tips_category_icon" />
<TextView
android:id="@+id/category_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:textColor="@android:color/white"
android:textSize="19sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/selector_tips_category_scrap_btn"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="17dp"
android:src="@drawable/tips_category_scrap_icon" />
<TextView
android:id="@+id/scrap_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="@string/scrap"
android:textColor="@color/c_298bcd"
android:textSize="19sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<ExpandableListView
android:id="@+id/expandable_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ExpandableListView>
</LinearLayout>
'프로그래밍 > Android' 카테고리의 다른 글
Android intent ACTION_VIEW valid url check (0) | 2015.02.17 |
---|---|
Android Load More ListView (0) | 2015.02.12 |
Android create keyhash from debug.keystore and release.keystore (0) | 2015.01.30 |
Android create keyhash (0) | 2015.01.26 |
Android about Alarmmanager... (0) | 2015.01.19 |
댓글