N
N
newdancer2017-01-29 00:13:19
Android
newdancer, 2017-01-29 00:13:19

How to access fragment adapter from activity?

How to refer to the adapter located in the fragment from the activity?
In MainActivity I send data to the fragment:

myCardFragment = new MyCardFragment();
myCardFragment.updateAdapter(newText);

in fragment method:
public void updateAdapter(String strSearch){
        if(myCardsAdapter != null){
            myCardsAdapter.filter(strSearch);
        }
    }

And actually in this method, the adapter always returns null, although it is currently open.
And actually I'm trying to transfer data from the search to the actionbar through SearchView.OnQueryTextListener to fragment to update the adapter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Agrass, 2017-02-17
@Agrass

Comrade gim0 suggested:

//...Some code here;
private MyCardsAdapter myCardsAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_view, container, false);
        myCardsAdapter = new MyCardsAdapter();
//     Some code here...;
        return view;
    }

You are missing a reference to myCardsAdapter because you probably don't declare it anywhere ( new Object;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question