所以我试图将子项的名称作为字符串获取,以便我可以将它添加到我收集的其他数据并将其插入到数据库中,但这种方法不起作用,我得到的只是名称父母的。
exp_list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
TextView the = (TextView) findViewById(R.id.child_txt);
String tx = the.getText().toString();
Toast.makeText(getBaseContext(), tx + " Child Clicked", Toast.LENGTH_SHORT).show();
// Store value in sharedPreferences();
Intent l = new Intent(CategoryActivity.this, AddRecipeActivity.class);
startActivity(l);
return false;
}
});
答案 0 :(得分:0)
尝试从适配器获取数据(您的String)而不是视图:
exp_list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
String tx = parent.getExpandableListAdapter().getChild(groupPosition, childPosition);// this will return your child Object (i guess String in your case)
Toast.makeText(getBaseContext(), tx + " Child Clicked", Toast.LENGTH_SHORT).show();
// Store value in sharedPreferences();
Intent l = new Intent(CategoryActivity.this, AddRecipeActivity.class);
startActivity(l);
return false;
}
});