Last active
September 29, 2017 09:22
-
-
Save wightwulf1944/b1b1b15ca0df6a205db07e427581b6ba to your computer and use it in GitHub Desktop.
scrollToPosition(int) doesnt work?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private int currentIndex; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
currentIndex = savedInstanceState.getInt("currentIndex"); | |
} | |
@Override | |
public void onBackPressed() { | |
if (getFragmentManager().getBackStackEntryCount() > 0) { | |
getFragmentManager().popBackStack(); | |
} else { | |
super.onBackPressed(); | |
} | |
} | |
public void setCurrentIndex(int i) { | |
currentIndex = i; | |
} | |
public int getCurrentIndex() { | |
return currentIndex; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.android.flexbox.FlexWrap; | |
import com.google.android.flexbox.FlexboxLayoutManager; | |
import com.google.android.flexbox.JustifyContent; | |
public class MasterFragment extends Fragment { | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
MainActivity parentActivity = (MainActivity) getActivity(); | |
int currentIndex = parentActivity.getCurrentIndex(); | |
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(parentActivity); | |
layoutManager.setFlexWrap(FlexWrap.WRAP); | |
layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND); | |
MasterAdapter adapter = new MasterAdapter(); | |
adapter.setData(//); | |
RecyclerView recyclerView = findById(view, R.id.recyclerView); | |
recyclerView.setHasFixedSize(true); | |
recyclerView.setLayoutManager(layoutManager); | |
recyclerView.setAdapter(adapter); | |
recyclerView.scrollToPosition(currentIndex); //POINT OF INTEREST | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment