Ho due frammenti su un cercapersone di visualizzazione. Una volta ho dovuto spostare i dati dal frammento B ad A e aggiornare i dati visualizzati su A e l'ho fatto con getItemPosition. Per qualche ragione, lo stesso metodo non funziona quando si tenta di ripristinare tutti i dati ..Visualizzazione dati di aggiornamento su un frammento
Nel mio adattatore ho:
public void refresh()
{
notifyDataSetChanged();
}
@Override
public int getItemPosition(Object obj)
{
return POSITION_NONE;
}
nel frammento in cui clicco 'reset':
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
notTriedPasswordsList = PagerActivity.mainList;
.....
....
resetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
PagerActivity.resetPasswords();
PagerActivity.viewPagerAdapter.refresh();
}});
attività viewPager ospitano entrambi i frammenti:
public static void resetPasswords()
{
mainList.addAll(0, historyList);
historyList.clear();
PagerActivity.viewPagerAdapter.refresh();
}
frammento principale whe re viene visualizzato il passaggio:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_main, container, false);
.....
nextCodeDisplay = (TextView) view.findViewById(R.id.passwordDisplayTextView);
nextCodeDisplay.setText(notTriedPasswordsList.get(0).getPasswordString());
....
nextButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
notTriedPasswordsList.remove(0);
if(notTriedPasswordsList.size() > 0 && !(notTriedPasswordsList.get(0).getTried()))
{
nextCodeDisplay.setText(notTriedPasswordsList.get(0).getPasswordString());
}
}
Come sono i tuoi progressi? Ho notato che non hai risposto di recente. –
usa l'interfaccia per la comunicazione tra due frammenti, funzionerà in questo modo ..... – TheGreat004