diff --git a/multi-level-listview/src/main/java/pl/openrnd/multilevellistview/MultiLevelListAdapter.java b/multi-level-listview/src/main/java/pl/openrnd/multilevellistview/MultiLevelListAdapter.java index 7f44197..5ec9d46 100644 --- a/multi-level-listview/src/main/java/pl/openrnd/multilevellistview/MultiLevelListAdapter.java +++ b/multi-level-listview/src/main/java/pl/openrnd/multilevellistview/MultiLevelListAdapter.java @@ -47,7 +47,7 @@ public abstract class MultiLevelListAdapter { /** * Gets list of object's sub-items. - * + *
* Called only for expandable objects.
*
* @param object The object.
@@ -58,13 +58,25 @@ public abstract class MultiLevelListAdapter {
/**
* Gets view configured to display the object.
*
- * @param object The object.
+ * @param object The object.
* @param convertView The view that can be reused if possible. Null value if not available.
- * @param itemInfo The InfoItem object with information about item location in MultiLevelListView.
+ * @param itemInfo The InfoItem object with information about item location in MultiLevelListView.
* @return The view that reflects the object.
*/
protected abstract View getViewForObject(Object object, View convertView, ItemInfo itemInfo);
+ /**
+ * Indicates if object is expanded initially.
+ * You can override this method to specify different objects' behaviour.
+ * This method will NOT be called if {@link #isExpandable(Object)} returns false or {@link MultiLevelListView#isAlwaysExpanded()} returns true.
+ *
+ * @param object The object.
+ * @return true if object is expanded, false otherwise.
+ */
+ protected boolean isInitiallyExpanded(Object object) {
+ return false;
+ }
+
/**
* Sets initial data items to be displayed in attached MultiLevelListView.
*
@@ -93,7 +105,7 @@ public void notifyDataSetChanged() {
/**
* Reloads data. Method is causing nodes recreation.
*/
- void reloadData() {
+ public void reloadData() {
setDataItems(mSourceData);
}
@@ -110,7 +122,7 @@ private void checkState() {
* Creates list of nodes for data items provided to adapter.
*
* @param dataItems List of objects for which nodes have to be created.
- * @param parent Node that is a parent for nodes created for data items.
+ * @param parent Node that is a parent for nodes created for data items.
* @return List with nodes.
*/
private List
* Adds sub-nodes to the node.
*
- * @param node The node.
+ * @param node The node.
* @param nestTyp NestType value.
*/
void extendNode(Node node, NestType nestTyp) {
@@ -221,7 +233,7 @@ void extendNode(Node node, NestType nestTyp) {
/**
* Collapse node.
- *
+ *
* Clears node's sub-nodes.
*
* @param node The node
diff --git a/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/DataActivity.java b/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/DataActivity.java
index c2a6903..7cbfc94 100644
--- a/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/DataActivity.java
+++ b/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/DataActivity.java
@@ -44,8 +44,10 @@ public class DataActivity extends Activity {
private MultiLevelListView mListView;
private Switch mMultipliedExpandingView;
private Switch mAlwaysExpandedView;
+ private Switch mInitiallyExpandedView;
private boolean mAlwaysExpandend;
+ private ListAdapter mListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -59,19 +61,21 @@ private void confViews() {
mListView = (MultiLevelListView) findViewById(R.id.listView);
mMultipliedExpandingView = (Switch) findViewById(R.id.multipledExpanding);
mAlwaysExpandedView = (Switch) findViewById(R.id.alwaysExpanded);
+ mInitiallyExpandedView = (Switch) findViewById(R.id.initiallyExpanded);
mMultipliedExpandingView.setOnCheckedChangeListener(mOnCheckedChangeListener);
mAlwaysExpandedView.setOnCheckedChangeListener(mOnCheckedChangeListener);
+ mInitiallyExpandedView.setOnCheckedChangeListener(mOnCheckedChangeListener);
setAlwaysExpanded(mAlwaysExpandedView.isChecked());
setMultipleExpanding(mMultipliedExpandingView.isChecked());
- ListAdapter listAdapter = new ListAdapter();
+ mListAdapter = new ListAdapter();
- mListView.setAdapter(listAdapter);
+ mListView.setAdapter(mListAdapter);
mListView.setOnItemClickListener(mOnItemClickListener);
- listAdapter.setDataItems(DataProvider.getInitialItems());
+ mListAdapter.setDataItems(DataProvider.getInitialItems());
}
private void setAlwaysExpanded(boolean alwaysExpanded) {
@@ -83,6 +87,12 @@ private void setMultipleExpanding(boolean multipleExpanding) {
mListView.setNestType(multipleExpanding ? NestType.MULTIPLE : NestType.SINGLE);
}
+ private void setInitiallyExpanded(boolean expanded) {
+ DataProvider.setGroup2InitiallyExpanded(expanded);
+ mListAdapter.reloadData();
+ }
+
+
private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -95,6 +105,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
case R.id.alwaysExpanded:
setAlwaysExpanded(isChecked);
break;
+ case R.id.initiallyExpanded:
+ setInitiallyExpanded(isChecked);
+ break;
}
}
};
@@ -140,6 +153,11 @@ public boolean isExpandable(Object object) {
return DataProvider.isExpandable((BaseItem) object);
}
+ @Override
+ protected boolean isInitiallyExpanded(Object object) {
+ return DataProvider.isInitiallyExpanded((BaseItem) object);
+ }
+
@Override
public View getViewForObject(Object object, View convertView, ItemInfo itemInfo) {
ViewHolder viewHolder;
diff --git a/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/data/DataProvider.java b/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/data/DataProvider.java
index e843c52..fead098 100644
--- a/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/data/DataProvider.java
+++ b/sample-app/src/main/java/pl/openrnd/multilevellistview/sample/data/DataProvider.java
@@ -28,24 +28,25 @@ public class DataProvider {
* Following variables refer only to data generation process.
* For instance, if ITEMS_PER_LEVEL = 2 and MAX_LEVELS = 3,
* list should look like this:
- * + 1
- * | + 1.1
- * | - - 1.1.1
- * | - - 1.1.2
- * | + 1.2
- * | - - 1.2.1
- * | - - 1.2.2
- * | - - 1.2.3
- * + 2
- * | + 2.1
- * | - - 2.1.1
- * | - - 2.1.2
- * | + 2.2
- * | - - 2.2.1
- * | - - 2.2.2
+ * + 1
+ * | + 1.1
+ * | - - 1.1.1
+ * | - - 1.1.2
+ * | + 1.2
+ * | - - 1.2.1
+ * | - - 1.2.2
+ * | - - 1.2.3
+ * + 2
+ * | + 2.1
+ * | - - 2.1.1
+ * | - - 2.1.2
+ * | + 2.2
+ * | - - 2.2.1
+ * | - - 2.2.2
*/
private static final int ITEMS_PER_LEVEL = 4;
private static final int MAX_LEVELS = 6;
+ private static boolean isGroup2InitiallyExpanded = false;
public static List