D
D
Denis Afonin2014-11-15 09:23:19
Android
Denis Afonin, 2014-11-15 09:23:19

How to update the data in the DialogFragment the next time it is called?

From the main activity, when I click on the ListView item, I call DialogFragment and pass parameters to it. On the first call, the data is displayed correctly, but on each subsequent call, the data is transferred, but the DialogFragment displays the old data. How can I make it show new data?
DialogFragment call code from Activity:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String dst, prc, fspd, raz, tm, rspd = "";
        Cursor c = db.getrec((int) id);
        c.moveToFirst();
        int firstrec = Integer.parseInt(c.getString(c.getColumnIndex("_id")));
        dst = c.getString(c.getColumnIndex("dist"));//Дистанция
        prc = c.getString(c.getColumnIndex("prc"));//Процент
        fspd = c.getString(c.getColumnIndex("fsp"));//ПДД
        raz = c.getString(c.getColumnIndex("raz"));//Разница
        tm = c.getString(c.getColumnIndex("tm"));//Время сектора
        rspd = c.getString(c.getColumnIndex("rsp"));

        Bundle args = new Bundle();
        args.putInt("id", (int) id);
        args.putString("dist", dst);
        args.putString("prc", prc);
        args.putString("fspd", fspd);
        args.putString("raz", raz);
        args.putString("rspd", rspd);
        args.putString("tm", 
        dlgrdlistchange.setArguments(args);
        dlgrdlistchange.show(getFragmentManager(),"dlgrdlistchange");

DialogFragmnet code:
public class rdlistchange extends DialogFragment implements OnClickListener {

    private OnCompliteListener mListener;
    private EditText listeditdist;
    private EditText listeditpercent;
    private EditText listeditspeed;
    final String LOG_TAG = "myLogs";
    private String dist, fspd, prc, raz, rspd, tm;
    Integer args;

    public rdlistchange(OnCompliteListener listener) {
        this.mListener = listener;
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        args = getArguments().getInt("id");
        dist = getArguments().getString("dist");
        prc = getArguments().getString("prc");
        fspd = getArguments().getString("fspd");
        raz = getArguments().getString("raz");
        rspd = getArguments().getString("rspd");
        tm = getArguments().getString("tm");

        getDialog().setTitle("Измените параметры участка РД");
        View v = inflater.inflate(R.layout.rdlistchange, null);
        v.findViewById(R.id.btnYes).setOnClickListener(this);
        v.findViewById(R.id.btnNo).setOnClickListener(this);
        listeditdist = (EditText) v.findViewById(R.id.listeditdist);
        listeditpercent = (EditText) v.findViewById(R.id.listeditpercent);
        listeditspeed = (EditText) v.findViewById(R.id.listeditspeed);
        listeditdist.setText(dist);
        listeditspeed.setText(fspd);
        listeditpercent.setText(prc);
        return v;
    }

    public void onClick(View v) {
        Log.d(LOG_TAG, "Dialog 1: " + ((Button) v).getText());
        switch (v.getId()){
            case R.id.btnYes:
                 double rsec = Double.valueOf(String.valueOf(Double.valueOf(tm)/1000));
                double rmin = rsec/60;
                double rhour = rmin/60;
                double zspeed = Double.valueOf(listeditspeed.getText().toString())*(Double.valueOf(listeditpercent.getText().toString())/100);
                double draz = (((rhour*(Double.valueOf(rspd)-zspeed))/zspeed)*3600);
                raz = String.valueOf(roundResult(draz));
                mListener.onComplete(listeditdist.getText().toString(), listeditpercent.getText().toString(), listeditspeed.getText().toString(),args, raz);
                dismiss();
                break;
            case R.id.btnNo:
                dismiss();
                break;
        }
    }

    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        Log.d(LOG_TAG, "Dialog 1: onDismiss");
    }


    public void onCancel(DialogInterface dialog) {
        super.onCancel(dialog);
        Log.d(LOG_TAG, "Dialog 1: onCancel");
    }

    double roundResult (double d) {
        d = d*10;
        int i = (int) Math.round(d);
        return (double) i/10;
    }
}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
nonrblGyN4ik, 2014-11-15
@nonrblGyN4ik

You take data from the database, pass it to dialogFragment, then do something with it, but you don't save anything back to the database.

D
Denis Afonin, 2014-11-15
@Afdenis

Back I save the main activity:

dlgrdlistchange = new rdlistchange(new OnCompliteListener() {
            @Override
            public void onComplete(String dist, String percent, String speed, Integer id, String raz) {
db.editRec(dist, percent, null, id, raz, null, speed);
getSupportLoaderManager().getLoader(0).forceLoad();
}}

But in this case it doesn't matter, because. the problem is different, how do i update the dialogFragment with the new data passed to it?

T
Tiberal, 2015-09-22
@Tiberal

Check if the old dialog fragment is removed from the fragment manager by closing it

S
Sergey Goryachev, 2017-02-07
@IIIu6ko

On a landing page, section is better.
Article is more suitable for a content area, such as articles, news, articles.

<header>...</header>
<section class="about">...</section>
<section class="work">...</section>
<section class="news">
   <h1>Наши новости</h1>
   <article>...</article>
   <article>...</article>
   <article>...</article>
</section>
<footer>...</footer>

A
Alexey Strukov, 2017-02-07
@pm_wanderer

It's better to use div and not bother)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question