Java – how to call arrayadapter constructor from fragment in Android

I'm trying to add a two - column listview to my android app When I create a project, I choose the fragment option, which creates a beautiful navigation by sliding left and right So my mainactivity extends fragmentactivity

My problem is that when I try to add addayadapter to listview, the constructor of arrayadapter looks for the context object, and I don't know to pass it

This is the wrong code I got

StableArrayAdapter adapter = new StableArrayAdapter(this,R.layout.row,list);
listview.setAdapter(adapter);

When I pass "this", it passes fragmentactivity because it extends fragmentactivity But the constructor needs a "context" object

It gives this error message

"The constructor MainActivity.StableArrayAdapter(MainActivity.DummySectionFragment,int,ArrayList<String>) is undefined"

How can I pass a context object?

Solution

You are setting up an adapter within the clip use

StableArrayAdapter adapter = new StableArrayAdapter(this.getActivity(),list);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>