Question

I'm updating my app by replacing all the deprecated methods. Now, I'm having problem with the DialogFragments.

I have a DialogActivity like this:

public class Actualizar extends FragmentActivity 
{
    /**BASIC ACTIVITY CODE HERE **/

    /**WHERE THAT I NEED HELP **/
    OnClickListener onClickListener = new OnClickListener()
    {
        @Override
        public void onClick(View v) 
        {
            AsyncTaskActualizarDatos task = new AsyncTaskActualizarDatos();
            task.execute();
        }
    };
}

When I click on a button I want execute am AsyncTask. This task should show a DialogFragment with a custom layout and download via FTP some file.

The AsyncTask is like this:

public class AsyncTaskActualizarDatos extends AsyncTask<Void,Void,Void>
{
    FragmentoComunicacion fragmento;

    @Override
    protected void onPreExecute() 
    {
        fragmento = FragmentoComunicacion.actualizarDatos();
        fragmento.show(fm, "dialog");
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... arg0) 
    {
          /** DO SOMETHING HERE **/
    }
}

And the fragment is like this:

public class FragmentoComunicacion extends DialogFragment
{
    public static FragmentoComunicacion actualizarDatos()
    {
        FragmentoComunicacion f = new FragmentoComunicacion();
        return f;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
        View v = inflater.inflate(R.layout.fragment_dialog_actualizar_datos, container);
        getDialog().setTitle("Title");
        return v;
    }
}

Now... I'm trying to update the views in the fragment (using publishProgress), but I don't know where I can do this. When I try to use fragmento.findView() in [doInBackground()] I got a nullPointerException.

I'm confused... What is the correct way to do this?

Thanks!

Was it helpful?

Solution

I believe the call you are looking for is:

fragmento.getDialog().findViewById(...)

OTHER TIPS

FragmentoComunicacion fragmento;

@Override
protected void onPreExecute() 
{
    FragmentoComunicacion fragmento = FragmentoComunicacion.actualizarDatos();
    fragmento.show(fm, "dialog");
    super.onPreExecute();
}

you're hiding your the parent field fragmento with local field fragmento, you need to change this:FragmentoComunicacion fragmento = FragmentoComunicacion.actualizarDatos(); to this:fragmento = FragmentoComunicacion.actualizarDatos();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top