رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

مشکل رفتن به فرگمنت


پست های پیشنهاد شده

با سلام

 من یک اکتیویتی رو تبدیل به فرگمنت کردم اما هنگامی که میخوام به اون فرگمنت برم از برنامه خارج میشم .میشه بگین کجای کارم اشکال داره ؟

[shcode=java]

package com.lemonweb.tejaratbank;

import android.app.Fragment;

import java.util.Timer;

import java.util.TimerTask;

import com.lemonweb.tejaratbank.R;

import com.lemonweb.tejaratbank.EditProfileFragment;

import com.lemonweb.tejaratbank.updateuserserver;

import android.app.ProgressDialog;

import android.content.Context;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

public class EditProfileFragment extends Fragment {

    private EditText name,family,oldpass,newpass,email;

    private TextView tname,tfamily,tuser,toldpass,tnewpass,temail,tstatus;

    private TextView user,status;

    private ImageView update,exit;

    public static String res="";

    private String pass="";

    private int count=0;

    private Context EditProfileFragment;

   

    public EditProfileFragment(){}

   

   

    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container,

            Bundle savedInstanceState) {

 

        View rootView = inflater.inflate(R.layout.fragment_editprofile, container, false);

        

tarif();

       

        Bundle extera=getActivity().getIntent().getExtras();

        final String s=extera.getString("username");

       

        user.setText(s);

       

        new updateuserserver("http://lemonweb.ugig.ir/update.php","","",s,"","","get");

       

        final Timer tm=new Timer();

        final ProgressDialog pd=new ProgressDialog(EditProfileFragment);

        pd.setMessage("لطفا صبر کنید"+"\n"+"در حال دریافت اطلاعات از سرور");

        pd.show();

       

        pd.setOnCancelListener(new ProgressDialog.OnCancelListener() {        

            @Override

            public void onCancel(DialogInterface arg0) {

               

                tm.cancel();

                pd.cancel();

                new updateuserserver("http://lemonweb.ugig.ir/update.php","","",s,"","","get").cancel(true);

               

               

            }

          });

       

        tm.scheduleAtFixedRate(new TimerTask(){

            public void run() {

                runOnUiThread(new Runnable(){

                    public void run() {

                       

                        count++;

                        if(count==30){

                           

                            pd.cancel();

                            tm.cancel();

                            count=0;

                            new updateuserserver("http://lemonweb.ugig.ir/update.php","","",s,"","","get").cancel(true);

                            Toast.makeText(getApplicationContext(), "خطا در برقراری ارتباط", Toast.LENGTH_LONG).show();

                            finish();

                           

                        }

                       

                        if(!res.equals("")){

                            pd.cancel();

                            po(res);

                            res="";

                            tm.cancel();

                           

                        }

                       

                       

                       

                    }

                    private void finish() {

                        // TODO Auto-generated method stub

                       

                    }

                    private Context getApplicationContext() {

                        // TODO Auto-generated method stub

                        return null;

                    }

                });

               

            }

   

        }, 1, 1000);

       

        update.setOnClickListener(new OnClickListener() {

           

            @Override

            public void onClick(View arg0) {

           

               

                if(!oldpass.getText().toString().equals("")){

                   

                    if(oldpass.getText().toString().equals(pass)){

                       

                        pass=newpass.getText().toString();

                    }else{

                       

                        Toast.makeText(getApplicationContext(), "wrong password", Toast.LENGTH_LONG).show();

                       

                    }

                   

                }

               

                new updateuserserver("http://lemonweb.ugig.ir/update.php",name.getText().toString(),family.getText().toString(),s,pass,email.getText().toString(),"put");

               

               

               

                final ProgressDialog pd=new ProgressDialog(EditProfileFragment);

                pd.setMessage("لطفا صبر کنید"+"در حال ارسال اطلاعات به سرور");

                pd.show();

               

               

                final Timer tm=new Timer();

                tm.scheduleAtFixedRate(new TimerTask(){

                    public void run() {

                        runOnUiThread(new Runnable(){

                            public void run() {

                               

                               

                                count++;

                                if(count==30){

                                   

                                    pd.cancel();

                                    tm.cancel();

                                    count=0;

                                    Toast.makeText(getApplicationContext(), "خطا در برقراری ارتباط", Toast.LENGTH_LONG).show();

                                   

                                   

                                }

                               

                                if(!res.equals("")){

                                    pd.cancel();

                                    Toast.makeText(getApplicationContext(), "updated!!!", Toast.LENGTH_LONG).show();

                                    tm.cancel();

                                }

                               

                               

                               

                            }

                            private Context getApplicationContext() {

                                // TODO Auto-generated method stub

                                return null;

                            }

                        });

                       

                    }

                    private void runOnUiThread(Runnable runnable) {

                        // TODO Auto-generated method stub

                       

                    }

           

                }, 1, 1000);

            }

        });

       

       

       

   

       

        return rootView;

    }

    protected void runOnUiThread(Runnable runnable) {

        // TODO Auto-generated method stub

       

    }

    protected Context getApplicationContext() {

        // TODO Auto-generated method stub

        return null;

    }

   

   

    private void tarif(){

       

        name=(EditText) getView().findViewById(R.id.edit_name_e);

        family=(EditText) getView().findViewById(R.id.edit_family_e);

        oldpass=(EditText) getView().findViewById(R.id.edit_oldpass_e);

        newpass=(EditText) getView().findViewById(R.id.edit_newpass_e);

        email=(EditText) getView().findViewById(R.id.edit_email_e);

       

        setTname((TextView) getView().findViewById(R.id.edit_name_t));

        setTfamily((TextView) getView().findViewById(R.id.edit_family_t));

        setTuser((TextView) getView().findViewById(R.id.edit_user_t));

        setToldpass((TextView) getView().findViewById(R.id.edit_oldpass_t));

        setTnewpass((TextView) getView().findViewById(R.id.edit_newpass_t));

        setTemail((TextView) getView().findViewById(R.id.edit_email_t));

        setTstatus((TextView) getView().findViewById(R.id.edit_status_t));

       

        user=(TextView) getView().findViewById(R.id.edit_user_e);

        status=(TextView) getView().findViewById(R.id.edit_status_e);

       

        update=(ImageView) getView().findViewById(R.id.edit_update_k);

        setExit((ImageView) getView().findViewById(R.id.edit_exit_k));

       

    }

   

@SuppressWarnings({ })

private void po(String temp){

       

       

        int f=0;

        int c=0;

        for(int i=0;i

           

            if(temp.charAt(i)=='|'){

               

                String t=temp.substring(f, i);

               

                if(c==0){

                   

                    name.setText(t);

                }

                if(c==1){

                   

                    family.setText(t);

                }

                if(c==2){

                   

                    pass=t;

                }

                if(c==3){

                   

                    email.setText(t);

                }

               

                if(c==4){

                   

                    if(t.equals("a")){

                        status.setText("کاربر فعال ");

                    }else if(t.equals("b")){

                        status.setText("کاربر بلاک شده");

                    }else if(t.equals("d")){

                        status.setText("کاربر غیر فعال");

                    }

                   

                }

               

               

               

                c+=1;

                f=i+1;

            }

           

           

           

        }

       

       

    }

public TextView getTemail() {

    return temail;

}

public void setTemail(TextView temail) {

    this.temail = temail;

}

public TextView getTnewpass() {

    return tnewpass;

}

public void setTnewpass(TextView tnewpass) {

    this.tnewpass = tnewpass;

}

public TextView getToldpass() {

    return toldpass;

}

public void setToldpass(TextView toldpass) {

    this.toldpass = toldpass;

}

public TextView getTuser() {

    return tuser;

}

public void setTuser(TextView tuser) {

    this.tuser = tuser;

}

public TextView getTfamily() {

    return tfamily;

}

public void setTfamily(TextView tfamily) {

    this.tfamily = tfamily;

}

public TextView getTname() {

    return tname;

}

public void setTname(TextView tname) {

    this.tname = tname;

}

public TextView getTstatus() {

    return tstatus;

}

public void setTstatus(TextView tstatus) {

    this.tstatus = tstatus;

}

public ImageView getExit() {

    return exit;

}

public void setExit(ImageView exit) {

    this.exit = exit;

}

   

}

[/shcode]

لینک ارسال
به اشتراک گذاری در سایت های دیگر

در تابع tarif() بجای getView() میبایستی از rootView که در ابتدای تابع oncreateView نوشته اید استفاده کنید

حالا برای پیدا کردن مشکل باید خط به خط برنامه را دیباگ کنید تا به نتیجه برسید و مشکل برطرف شود

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...