Recycleview Renew onCreateView как я могу это сделать - PullRequest
0 голосов
/ 05 мая 2020

Я новичок в разработке Android, и если пользователь видит F1 (см. Данные), а затем переходит к F2 (изменяет данные) и возвращается, F1 (эти данные старые данные) не является изменением формы F2 пользователя data
поэтому я хочу снова получить данные F1, пожалуйста, помогите мне

Сообщение об ошибке

E/error: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference

Я думаю, может быть мой Rel не инициализация, я не знаю, пожалуйста, дайте мне предложение

tab1:

Fragment1 fragment = new Fragment1();
            fragment.change();

Fragment1

если использование onLazyLoad правильное, но когда я использую «call», имеет значение null

public class Fragment1 extends BaseLazyFragment {

private String url = "http://211.22.XXX.XXX/xampp/";
private RecyclerView Re1;
private int page = 1,run=0;
private String user_id,phone,cookie;
private TextView text1,text2,text3;
private Context context;
private boolean isFirstLoad = false;
private RecyclerView.LayoutManager mLayoutManager;

@Override
public void onLazyLoad() {
    initData();
    isFirstLoad =true;
}
public void change(){
    Log.e("change",toString());
    initData();
    run =1;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_fragment1, container, false);

    initView(view);
    context = view.getContext();
    if(isFirstLoad){
        initData();
    }
    return view;
}
private void initView(View view){
    Re1 = view.findViewById(R.id.Re1_tab1);
    GlobalVariable Account = (GlobalVariable)getActivity().getApplicationContext();
    user_id = Account.getUser_id();
    phone = Account.getPhone();
    cookie = Account.getCookie();

}

private void initData(){
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()   // or .detectAll() for all detectable problems
            .penaltyLog()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects()
            .penaltyLog()
            .penaltyDeath()
            .build());
    Handler myHandler = new Handler();
    myHandler.postDelayed(runTimerStop,400);
    if(cookie != null) {
        myHandler.removeCallbacks(runTimerStop);
    }
}
private Runnable runTimerStop = new Runnable() {
    @Override
    public void run() {
        select(user_id);

       // dialog.dismiss();
    }
};

private void select(String id){
    try {
        String r = DBphp.DBstr(id,cookie,url);
        JSONArray jsonArray = new JSONArray(r);
        ArrayList<Rel_list> items = new ArrayList<Rel_list>();
        for (int i=0;i<jsonArray.length();i++){
            JSONObject jsonData = jsonArray.getJSONObject(i);
            items.add(new Rel_list(jsonData.getString("id"),jsonData.getString("product_name"),jsonData.getString("specification")
                    ,jsonData.getString("selling_price"),jsonData.getString("operations_center"),jsonData.getString("inventory"),jsonData.getString("pictuture_id"),jsonData.getString("ANS")));
        }

        RelAdapter SA = new RelAdapter(getContext(),items);

        Re1.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        Re1.setAdapter(SA);
        SA.setOnItemClickListener(new RelAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int i) {
              //  byte buff[] = new byte[125*250];
                ImageView im0 = view.findViewById(R.id.img_id);
                TextView te0 = view.findViewById(R.id.t1);
                TextView te1 = view.findViewById(R.id.t2);
                TextView te2 = view.findViewById(R.id.t3);
                TextView te3 = view.findViewById(R.id.t4);
                TextView te4 = view.findViewById(R.id.t5);
                TextView te5 = view.findViewById(R.id.t6);
                TextView te6 = view.findViewById(R.id.t7);
                TextView te7 = view.findViewById(R.id.t14);
                Intent intent= new Intent();
                intent.setClass(getContext(), shop_thing.class);
                Bundle bundle = new Bundle();
                bundle.putString("user_id",user_id);
                bundle.putString("user_phone",phone);
                bundle.putString("cookie",cookie);
                bundle.putString("page", String.valueOf(page));
                bundle.putString("shop_id",te0.getText().toString());
                bundle.putString("shop_product_name",te1.getText().toString());
                bundle.putString("shop_specification",te2.getText().toString());
                bundle.putString("shop_selling_price",te3.getText().toString());
                bundle.putString("shop_operations_center",te4.getText().toString());
                bundle.putString("shop_inventory",te5.getText().toString());
                bundle.putString("picture_id",te6.getText().toString());
                bundle.putString("love",te7.getText().toString());

                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }catch (Exception e){
        Log.e("error",e.toString());
    }
}

} home enter image description here F1 enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...