android getchild view,android - getChildView not being called - Stack Overflow

I am making a menu which includes a custom ExpandableListView adapter. Despite trying to match my code as close to the API examples and any other examples I've seen online (including multiple closely related SO questions), I still can't get it working.

I know the adapter is being used because the group view is being shown (which is made from an xml). Clicking on the group item also calls "getGroupView", but the code never runs "getChildView", "getChild", or "getChildId".

I've even went through the Android-15 source code to find out what I might have done wrong, but nothing odd has came up.

= Base Activity

public class SettingsM extends FragmentActivity

{

static Context context;

ViewPager mViewPager;

CollectionPagerAdapter mDemoCollectionPagerAdapter;

//ColorPicker picker;

SharedPreferences preferences;

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

context = this;

// Set up action bar.

final ActionBar actionBar = getActionBar();

actionBar.setDisplayHomeAsUpEnabled(false);

actionBar.setDisplayUseLogoEnabled(false);

actionBar.setTitle("Particle emitter settings");

// get the preferences for this screen

preferences = this.getSharedPreferences("base_world", 0);

// tab holder

setContentView(R.layout.tabmenu_holder);

mViewPager = (ViewPager) findViewById(R.id.pager);

mDemoCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());

mViewPager.setAdapter(mDemoCollectionPagerAdapter);

}

public class CollectionPagerAdapter extends FragmentStatePagerAdapter

{

public CollectionPagerAdapter(FragmentManager fm)

{

super(fm);

}

@Override

public Fragment getItem(int i)

{

Fragment fragment = new TabFragment();

Bundle args = new Bundle();

if(preferences != null)

{

if(i == 0)

{// world

args.putBoolean("world", true);

} else

{// emitter

args.putBoolean("world", false);

args.putInt("emitter", i-1);

}

}

fragment.setArguments(args);

return fragment;

}

@Override

public int getCount()

{

return 100;

}

@Override

public CharSequence getPageTitle(int position)

{

if(position == 0)

{

return "World";

} else

{

return "Emitter #" + position;

}

}

}

public static class TabFragment extends Fragment

{

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

{

Bundle args = getArguments();

View rootView = new TextView(context);// use a textview as the default

if(args.getBoolean("world"))

{

rootView = inflater.inflate(R.layout.m_backdrop, container, false);

// add face drop-down

ExpandableListView face_list = (ExpandableListView) rootView.findViewById(R.id.FaceList);

if(face_list != null)

{

face_list.setAdapter(new ExpandableFaceList(context));

face_list.setOnGroupClickListener(new OnGroupClickListener()

{

@Override

public boolean onGroupClick(ExpandableListView parent,

View v, int groupPosition, long id)

{

Log.i("FaceList", "Clicked:" + groupPosition);

return false;

}

});

}

} else

{

return rootView;

}

return rootView;

}

}

}

= Expandable List view Adapter

public class ExpandableFaceList extends BaseExpandableListAdapter implements ExpandableListAdapter

{

public Context context;

private LayoutInflater inflator;

private float mDensity = 1f;

private boolean bShowSw = true;

private ColorPickerMenuView cp;

private Switch sw;

public ExpandableFaceList(Context context)

{

this.context = context;

this.inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

mDensity = context.getResources().getDisplayMetrics().density;

}

@Override

public int getGroupCount()

{

return 1;

}

@Override

public int getChildrenCount(int groupPosition)

{

return 6;// because there are 6 faces to a cube

}

// list views

@Override

public View getGroupView(int groupPosition, boolean isExpanded,

View convertView, ViewGroup parent)

{

View v = convertView;

TextView tv;

if(v == null)

{

v = inflator.inflate(R.layout.exlist_head, parent, false);

tv = (TextView) v.findViewById(R.id.exList_Title);

if(tv != null)

tv.setText("Face Colors");

tv = (TextView) v.findViewById(R.id.exList_Summary);

String s_text = "The color for each face, click to ";

s_text += ((isExpanded)? "collaspe": "expand");

if(tv != null)

tv.setText(s_text);

} else

{

tv = (TextView) v.findViewById(R.id.exList_Summary);

String s_text = "The color for each face, click to ";

s_text += ((isExpanded)? "collaspe": "expand");

if(tv != null)

tv.setText(s_text);

parent.invalidate();

}

return v;

}

@Override

public View getChildView(int groupPosition, int childPosition,

boolean isLastChild, View convertView, ViewGroup parent)

{

View v = convertView;

if(v == null)

{

if(bShowSw)

{

v = (LinearLayout) inflator.inflate(R.layout.face_info_sw, parent, false);

} else

{

v = (LinearLayout) inflator.inflate(R.layout.face_info, parent, false);

}

}

switch(childPosition)

{

case 0:

v.setTag("Front");

break;

case 1:

v.setTag("Back");

break;

case 2:

v.setTag("Left");

break;

case 3:

v.setTag("Right");

break;

case 4:

v.setTag("Top");

break;

case 5:

v.setTag("Bottom");

break;

}

Log.i("ELV", "Pos:" + childPosition);

cp = (ColorPickerMenuView) v.findViewById(R.id.face_color);

cp.setTitle((String) v.getTag());

cp.setOnClickListener(new OnClickListener() {

public void onClick(View v) { UpdateData(v); }

});

if(bShowSw)

{

sw = (Switch) v.findViewById(R.id.face_sw);

sw.setOnClickListener(new OnClickListener() {

public void onClick(View v) { UpdateData(v); }

});

}

return v;

}

private void UpdateData(View v) { }

@Override

public Object getGroup(int groupPosition)

{

return groupPosition;

}

@Override

public Object getChild(int groupPosition, int childPosition)

{

return "Child:" + groupPosition + "." + childPosition;

}

@Override

public long getGroupId(int groupPosition)

{

return groupPosition;

}

@Override

public long getChildId(int groupPosition, int childPosition)

{

return childPosition;

}

@Override

public boolean hasStableIds()

{

return true;

}

@Override

public boolean isChildSelectable(int groupPosition, int childPosition)

{

return true;

}

}

= Activity's xml view

android:id="@+id/pager"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="top"

android:background="#33b5e5"

android:textColor="#fff"

android:paddingTop="4dp"

android:paddingBottom="4dp" />

= m_backdrop.xml (menu for the backdrop setting)

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:app="http://schemas.android.com/apk/res/com.zyphronics.aquafinger">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

android:id="@+id/Title_GeneralSettings_text"

style="?android:attr/listSeparatorTextViewStyle"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="5dip"

android:text="General Settings" />

android:id="@+id/FaceList"

android:layout_width="match_parent"

android:layout_height="fill_parent"

android:layout_below="@id/Title_GeneralSettings_text" >

= face_info.sw.xml (The face_info.xml is the same, but without the switch)

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

android:id="@+id/face_sw"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="10dp"

android:tag="face_sw"

android:text="Enabled?"

android:textOff="No"

android:textOn="Yes" />

android:id="@+id/face_color"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:tag="face_color" />

Even without the "ColorPickerMenuView" part in the face_info_sw.xml, the child view is still not being called. I've also tried having the Relative Layout by itself, instead of in a scroll view, but this prevented further added items from being scrolled to (and also made custom controls have weird sizes).

Any help to solve this would be great. If anyone needs a packaged source of this (eclipse compatible), as in the comments and I'll reply with a link.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值