Vote count:
0
I'm having trouble trying to use the ExpadableListItemAdapter. According to this link all I need to do is override the adapter's getTitleView and getContentView. So I wrote a test app using this adapter:
public class ListItemAdapter extends ExpandableListItemAdapter<String> {
Context mContext;
List mList;
public ListItemAdapter(Context context, List<String> list){
super(context, R.layout.activity_main, R.id.top, R.id.bottom, list);
mContext = context;
mList = list;
}
@Override
public View getTitleView(int position, View convertView, ViewGroup parent){
TextView textView;
if(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);
}
RelativeLayout rel = (RelativeLayout) convertView.findViewById(R.id.top);
textView = (TextView)rel.getChildAt(0);
textView.setText("click me!" + mList.get(position));
return textView;
}
@Override
public View getContentView(int position, View convertView, ViewGroup parent){
TextView textView;
if(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);
}
RelativeLayout rel = (RelativeLayout) convertView.findViewById(R.id.bottom);
textView = (TextView)rel.getChildAt(1);
textView.setText("what up!" + mList.get(position));
return textView;
}
}
The doc also says that I should " Create a new instance of your ExpandableListItemAdapter, call setAbsListView on it, and set it to your ListView " but there is no setAbsListView method for this adapter. So I tried to set it on an AlphaInAnimationAdapter as I've seen on other examples like so:
public class MainActivity extends Activity {
@InjectView(android.R.id.list)ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
List<String> list = new ArrayList<String>();
list.add("test 1");
list.add("test 2");
ListItemAdapter adapter = new ListItemAdapter(this, list);
AlphaInAnimationAdapter alpha = new AlphaInAnimationAdapter(adapter);
alpha.setAbsListView(mListView);
mListView.setAdapter(adapter);
}
But I still keep getting a NullPointerException error when I run the app:
09-21 18:18:23.392 16952-16952/ward.rydell.expandablelistexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ward.rydell.expandablelistexample, PID: 16952
java.lang.NullPointerException
at com.nhaarman.listviewanimations.itemmanipulation.expandablelistitem.ExpandableListItemAdapter.getView(ExpandableListItemAdapter.java:173)
at android.widget.AbsListView.obtainView(AbsListView.java:2765)
at android.widget.ListView.makeAndAddView(ListView.java:1801)
at android.widget.ListView.fillDown(ListView.java:697)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1641)
at android.widget.AbsListView.onLayout(AbsListView.java:2578)
at android.view.View.layout(View.java:15745)
at android.view.ViewGroup.layout(ViewGroup.java:4868)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:15745)
at android.view.ViewGroup.layout(ViewGroup.java:4868)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15745)
at android.view.ViewGroup.layout(ViewGroup.java:4868)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:459)
at android.view.View.layout(View.java:15745)
at android.view.ViewGroup.layout(ViewGroup.java:4868)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15745)
at android.view.ViewGroup.layout(ViewGroup.java:4868)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2333)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2046)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6585)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
What am i doing wrong. Do i need to add a getView method even though that wasn't specified? If so, how should it be implemented?
asked 1 min ago
ExpandableListItemAdapter from ListViewAnimations library giving me error
Aucun commentaire:
Enregistrer un commentaire