Update Textview on onResume

Asked

Viewed 277 times

6

package br.com.automaserv.stocserv.fragments;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import br.com.automaserv.stocserv.R;
import br.com.automaserv.stocserv.StocApplication;
import br.com.automaserv.stocserv.activities.FichaItemProdutoActivity;
import br.com.automaserv.stocserv.model.ORM;

public class ListaProdutosVendaFragment extends StocStringListFragment<ORM.ItemVenda, FichaItemProdutoActivity> {

private TextView tvSubtotal;
private StocApplication app;

public ListaProdutosVendaFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = super.onCreateView(inflater, container, savedInstanceState);

    loadAllOnResume = true;

    tvSubtotal   = (TextView) view.findViewById(R.id.tvSubTotal);

    app = getApp();

    return view;
}

@Override
public void onStart() {
    startTask();
}

private void startTask() {
    new Task().execute();
}
private class Task extends AsyncTask<Void, Void, Void> {
    private String text;

    @Override
    protected Void doInBackground(Void... voids) {
        Log.d("test","doInBackground");
        this.text = "funcionou";
        return null;
    }

    protected void onPostExecute(Void result) {
        Log.d("test","onPostExecute");
        tvSubtotal.setText(text);
    }
}

@Override
protected Class<FichaItemProdutoActivity> getActivityClassName() {
    return FichaItemProdutoActivity.class;
}

@Override
protected void loadAll() {
    replaceData( app.itensVenda );
}

@Override
public boolean onQueryTextSubmit(String query) {
    List<ORM.Produto> res = ORM.Produto.buscar( query );
    replaceData(res);
    return true;
}

@Override
protected int getLayoutResourceId() {
    return R.layout.lista_produtos_venda_fragment;
}

}

Hello everyone! I have the following fragment described above and I need to update the contents of Textview tvSubtotal whenever the fragment is reexibido. The fragment is a list of items and should display the sum of the added items. However, I am always getting the error "Did not call through to super.onResume()"

1 answer

7


You should not be calling the super.onResume();

Try to do it that way:

@Override
public void onResume(){
    super.onResume();
}

Obligatorily, calling the @Override and the super.onResume

  • 2

    Only supplemented, all methods of the Activity life click must first of all call their respective methods of the parent class, super.onResume(), super.onPause(), super.onStop() and so on...

  • 1

    Complementing a little more, you should pass the update you want inside the onResume(), after super.OnResume().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.