0
我可以將數據拉出孩子和吐司消息。但是如果我嘗試使用我的Communicator接口,它會立即崩潰。 Communicator對我所有其他片段和片段列表都可以正常工作。無論我從哪裏調用ExpandableListView片段的基本toastMessage方法,它都會不斷崩潰。片段Communicator接口調用ExpandableListView不起作用
/**
* Created by petakirikiri on 3/03/16.
*/
public class ThingsInputFragmentExpandableList extends Fragment {
View v;
HashMap<String, List<String>> movies_category;
List<String> movies_list;
ExpandableListView Exp_list;
MoviesAdapter adapter;
Communicator comm;
public ThingsInputFragmentExpandableList() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.movies_expandablelist_fragment, container, false);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
super.onCreate(savedInstanceState);
Exp_list = (ExpandableListView) v.findViewById(R.id.exp_list);
movies_category = ThingsDataProvider.getInfo();
movies_list = new ArrayList<String>(movies_category.keySet());
adapter = new MoviesAdapter(getActivity(), movies_category, movies_list);
Exp_list.setAdapter(adapter);
Exp_list.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getActivity(), movies_list.get(groupPosition) + " is expanded", Toast.LENGTH_LONG).show();
}
});
Exp_list.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getActivity(), movies_list.get(groupPosition) + " is collapsed", Toast.LENGTH_LONG).show();
}
});
Exp_list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (movies_list.get(groupPosition) == "Determiners"){
comm.toastMessageTest();
}
else if (movies_list.get(groupPosition) == "Things"){
}
else if (movies_list.get(groupPosition) == "Adjectives"){
}
return false;
}
});
}
}
public interface Communicator {
public void toastMessageTest();
public void setIntransitiveFragment();
public void setTransitiveFragment();
public void setPronounFragment();
public void setThingFragment();
public void setLocationFragment();
public void setVerb(String data);
public void setTense(String data);
public void setSubject(String data);
public void setDeterminerSubject(String data);
public void setThingSubject(String data);
public void setAdjectiveSubject(String data);
}
public class MainActivity extends Activity implements Communicator{
@Override
public void toastMessageTest() {
Toast.makeText(this, "This works", Toast.LENGTH_LONG).show();
}
}
這與您的問題無關,但我相信,您應避免使用ExpandableListView,它已過時並且不屬於最新的設計指南。 –