0

I am try to figure out the Android Adapter how to associate with AdapterView.But I didn't understand the following code:

@Override
public void setAdapter(ListAdapter adapter) {
    if (mAdapter != null && mDataSetObserver != null) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
    }

    resetList();
    mRecycler.clear();        
    mAdapter = adapter;

    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    // AbsListView#setAdapter will update choice mode states.
    super.setAdapter(adapter);

    if (mAdapter != null) {
        mOldItemCount = mItemCount;
        mItemCount = mAdapter.getCount();
        mDataChanged = true;
        checkFocus();

        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        mRecycler.setViewTypeCount(mAdapter.getViewTypeCount());

        int position;
        if (mStackFromBottom) {
            position = lookForSelectablePosition(mItemCount - 1, false);
        } else {
            position = lookForSelectablePosition(0, true);
        }
        setSelectedPositionInt(position);
        setNextSelectedPositionInt(position);
        checkSelectionChanged();
    } else {
        checkFocus();            
        // Nothing selected
        checkSelectionChanged();
    }

    requestLayout();
}

I didn't know where the variable mAdapter come from and I didn't understand why the code in this method can't to click to associate with associated method in Eclipse,Are they implementation in
native method ?

dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
Thomas
  • 177
  • 1
  • 3
  • `mAdapter` is a member of the class this method is in, or a protected member a class that is inherited. – andy256 Jul 25 '13 at 08:06
  • Android's setAdapter() method is same as the one you do for a listview . The mAdapter here must have been defined elsewhere in your code. Although from the code posted its difficult to understand what you want to achieve. Are you trying to implement a simple gridView? – user2041902 Jul 25 '13 at 08:07
  • The posted code above was android.widget.GridView#setAdapter method,you can find it in Android source code. – Thomas Jul 27 '13 at 10:07

1 Answers1

0

mAdapter is inherite from parent class: android.widget.AbsListView. They are not native code, I think it is Eclipse issue for not able to click to go to corresponding methods.

LiuWenbin_NO.
  • 1,216
  • 1
  • 16
  • 25