Now I'm trying to the transparent opensource expandable layout but the problem is that source made by activity but I want to apply my fragment layout what should I do? When I try to transparent it's occurred error...
****This is what I want to try transparent****
package com.expandablelistdemo;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;
import com.expandablelistdemo.Model.DataItem;
import com.expandablelistdemo.Model.SubCategoryItem;
import java.util.ArrayList;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
private Button btn;
private ExpandableListView lvCategory;
private ArrayList<DataItem> arCategory;
private ArrayList<SubCategoryItem> arSubCategory;
private ArrayList<ArrayList<SubCategoryItem>> arSubCategoryFinal;
private ArrayList<HashMap<String, String>> parentItems;
private ArrayList<ArrayList<HashMap<String, String>>> childItems;
private MyCategoriesExpandableListAdapter myCategoriesExpandableListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,CheckedActivity.class);
startActivity(intent);
}
});
setupReferences();
}
private void setupReferences() {
lvCategory = findViewById(R.id.lvCategory);
arCategory = new ArrayList<>();
arSubCategory = new ArrayList<>();
parentItems = new ArrayList<>();
childItems = new ArrayList<>();
DataItem dataItem = new DataItem();
dataItem.setCategoryId("1");
dataItem.setCategoryName("Adventure");
arSubCategory = new ArrayList<>();
for(int i = 1; i < 6; i++) {
SubCategoryItem subCategoryItem = new SubCategoryItem();
subCategoryItem.setCategoryId(String.valueOf(i));
subCategoryItem.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
subCategoryItem.setSubCategoryName("Adventure: "+i);
arSubCategory.add(subCategoryItem);
}
dataItem.setSubCategory(arSubCategory);
arCategory.add(dataItem);
dataItem = new DataItem();
dataItem.setCategoryId("2");
dataItem.setCategoryName("Art");
arSubCategory = new ArrayList<>();
for(int j = 1; j < 6; j++) {
SubCategoryItem subCategoryItem = new SubCategoryItem();
subCategoryItem.setCategoryId(String.valueOf(j));
subCategoryItem.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
subCategoryItem.setSubCategoryName("Art: "+j);
arSubCategory.add(subCategoryItem);
}
dataItem.setSubCategory(arSubCategory);
arCategory.add(dataItem);
dataItem = new DataItem();
dataItem.setCategoryId("3");
dataItem.setCategoryName("Cooking");
arSubCategory = new ArrayList<>();
for(int k = 1; k < 6; k++) {
SubCategoryItem subCategoryItem = new SubCategoryItem();
subCategoryItem.setCategoryId(String.valueOf(k));
subCategoryItem.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
subCategoryItem.setSubCategoryName("Cooking: "+k);
arSubCategory.add(subCategoryItem);
}
dataItem.setSubCategory(arSubCategory);
arCategory.add(dataItem);
Log.d("TAG", "setupReferences: "+arCategory.size());
for(DataItem data : arCategory){
// Log.i("Item id",item.id);
ArrayList<HashMap<String, String>> childArrayList =new ArrayList<HashMap<String, String>>();
HashMap<String, String> mapParent = new HashMap<String, String>();
mapParent.put(ConstantManager.Parameter.CATEGORY_ID,data.getCategoryId());
mapParent.put(ConstantManager.Parameter.CATEGORY_NAME,data.getCategoryName());
int countIsChecked = 0;
for(SubCategoryItem subCategoryItem : data.getSubCategory()) {
HashMap<String, String> mapChild = new HashMap<String, String>();
mapChild.put(ConstantManager.Parameter.SUB_ID,subCategoryItem.getSubId());
mapChild.put(ConstantManager.Parameter.SUB_CATEGORY_NAME,subCategoryItem.getSubCategoryName());
mapChild.put(ConstantManager.Parameter.CATEGORY_ID,subCategoryItem.getCategoryId());
mapChild.put(ConstantManager.Parameter.IS_CHECKED,subCategoryItem.getIsChecked());
if(subCategoryItem.getIsChecked().equalsIgnoreCase(ConstantManager.CHECK_BOX_CHECKED_TRUE)) {
countIsChecked++;
}
childArrayList.add(mapChild);
}
if(countIsChecked == data.getSubCategory().size()) {
data.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_TRUE);
}else {
data.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
}
mapParent.put(ConstantManager.Parameter.IS_CHECKED,data.getIsChecked());
childItems.add(childArrayList);
parentItems.add(mapParent);
}
ConstantManager.parentItems = parentItems;
ConstantManager.childItems = childItems;
myCategoriesExpandableListAdapter = new MyCategoriesExpandableListAdapter(this,parentItems,childItems,false);
lvCategory.setAdapter(myCategoriesExpandableListAdapter);
}
}
**** This is my Fragment Activity ****
public class TabFragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab_fragment_1, container, false);
}
}
I'm trying to several days but I can't find how to do...
Any suggestion or help is welcome
Here you go:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ExpandableListView;
import androidx.fragment.app.Fragment;
import com.expandablelistdemo.Model.DataItem;
import com.expandablelistdemo.Model.SubCategoryItem;
import java.util.ArrayList;
import java.util.HashMap;
public class TabFragment1 extends Fragment {
private Button btn;
private ExpandableListView lvCategory;
private ArrayList<DataItem> arCategory;
private ArrayList<SubCategoryItem> arSubCategory;
private ArrayList<ArrayList<SubCategoryItem>> arSubCategoryFinal;
private ArrayList<HashMap<String, String>> parentItems;
private ArrayList<ArrayList<HashMap<String, String>>> childItems;
private MyCategoriesExpandableListAdapter myCategoriesExpandableListAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_1, container, false);
btn = view.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CheckedActivity.class);
startActivity(intent);
}
});
setupReferences(view);
return view;
}
private void setupReferences(View view) {
lvCategory = view.findViewById(R.id.lvCategory);
arCategory = new ArrayList<>();
arSubCategory = new ArrayList<>();
parentItems = new ArrayList<>();
childItems = new ArrayList<>();
DataItem dataItem = new DataItem();
dataItem.setCategoryId("1");
dataItem.setCategoryName("Adventure");
arSubCategory = new ArrayList<>();
for (int i = 1; i < 6; i++) {
SubCategoryItem subCategoryItem = new SubCategoryItem();
subCategoryItem.setCategoryId(String.valueOf(i));
subCategoryItem.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
subCategoryItem.setSubCategoryName("Adventure: " + i);
arSubCategory.add(subCategoryItem);
}
dataItem.setSubCategory(arSubCategory);
arCategory.add(dataItem);
dataItem = new DataItem();
dataItem.setCategoryId("2");
dataItem.setCategoryName("Art");
arSubCategory = new ArrayList<>();
for (int j = 1; j < 6; j++) {
SubCategoryItem subCategoryItem = new SubCategoryItem();
subCategoryItem.setCategoryId(String.valueOf(j));
subCategoryItem.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
subCategoryItem.setSubCategoryName("Art: " + j);
arSubCategory.add(subCategoryItem);
}
dataItem.setSubCategory(arSubCategory);
arCategory.add(dataItem);
dataItem = new DataItem();
dataItem.setCategoryId("3");
dataItem.setCategoryName("Cooking");
arSubCategory = new ArrayList<>();
for (int k = 1; k < 6; k++) {
SubCategoryItem subCategoryItem = new SubCategoryItem();
subCategoryItem.setCategoryId(String.valueOf(k));
subCategoryItem.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
subCategoryItem.setSubCategoryName("Cooking: " + k);
arSubCategory.add(subCategoryItem);
}
dataItem.setSubCategory(arSubCategory);
arCategory.add(dataItem);
Log.d("TAG", "setupReferences: " + arCategory.size());
for (DataItem data : arCategory) {
// Log.i("Item id",item.id);
ArrayList<HashMap<String, String>> childArrayList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> mapParent = new HashMap<String, String>();
mapParent.put(ConstantManager.Parameter.CATEGORY_ID, data.getCategoryId());
mapParent.put(ConstantManager.Parameter.CATEGORY_NAME, data.getCategoryName());
int countIsChecked = 0;
for (SubCategoryItem subCategoryItem : data.getSubCategory()) {
HashMap<String, String> mapChild = new HashMap<String, String>();
mapChild.put(ConstantManager.Parameter.SUB_ID, subCategoryItem.getSubId());
mapChild
.put(ConstantManager.Parameter.SUB_CATEGORY_NAME, subCategoryItem.getSubCategoryName());
mapChild.put(ConstantManager.Parameter.CATEGORY_ID, subCategoryItem.getCategoryId());
mapChild.put(ConstantManager.Parameter.IS_CHECKED, subCategoryItem.getIsChecked());
if (subCategoryItem.getIsChecked()
.equalsIgnoreCase(ConstantManager.CHECK_BOX_CHECKED_TRUE)) {
countIsChecked++;
}
childArrayList.add(mapChild);
}
if (countIsChecked == data.getSubCategory().size()) {
data.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_TRUE);
} else {
data.setIsChecked(ConstantManager.CHECK_BOX_CHECKED_FALSE);
}
mapParent.put(ConstantManager.Parameter.IS_CHECKED, data.getIsChecked());
childItems.add(childArrayList);
parentItems.add(mapParent);
}
ConstantManager.parentItems = parentItems;
ConstantManager.childItems = childItems;
myCategoriesExpandableListAdapter = new MyCategoriesExpandableListAdapter(this, parentItems,
childItems, false);
lvCategory.setAdapter(myCategoriesExpandableListAdapter);
}