Android "fragment uchun identifikator topilmadi"

Xop. Men siqilib qolaman va boshim og'riyapti ... Men shubhasiz ishlamaydi, chunki boshqa laymaning nuqtai nazaridan qanday foydalanish mumkinligiga ishonchim komil emas. Mana mening kodlarim.

WriteRouteActivity.java

public class WriteRouteActivity extends AppCompatActivity {

    private Toolbar tb;
    private TextView txt_toolbar_title;
    private Button btnSearchPlaces;
    private LinearLayout parentLayout, placesCoverLayout;
    private View popupView;
    private ImageView imgShowPlaces;
    private boolean isKeyBoardVisible;
    private int keyboardHeight;
    private EditText edtSearchPlaces;
    private PopupWindow popupWindow;

    //popupView
    private TabLayout tabLayout;
    private FrameLayout frameLayout;

    //prework
    private int minusVal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_write_route);
        initView();

    }

    private void initView() {
        //for activity and native back button

        tb = (Toolbar) findViewById(R.id.nav_toolbar);
        setSupportActionBar(tb);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        txt_toolbar_title = (TextView) findViewById(R.id.txt_toolbar);

        parentLayout = (LinearLayout) findViewById(R.id.layout_parent);
        placesCoverLayout = (LinearLayout) findViewById(R.id.footer_for_places);
        imgShowPlaces = (ImageView) findViewById(R.id.img_show_places);
        edtSearchPlaces =(EditText) findViewById(R.id.edt_search_place);
        btnSearchPlaces = (Button) findViewById(R.id.btn_search_place);

        popupView = getLayoutInflater().inflate(R.layout.places_popup, null);
        tabLayout = (TabLayout) popupView.findViewById(R.id.tab_layout);
        frameLayout = (FrameLayout) popupView.findViewById(R.id.frame_layout);

        doWorkForLayotus();
    }

    private void doWorkForLayotus(){
        final float popUpheight = getResources().getDimension(R.dimen.keyboard_height);
        changeKeyboardHeight((int) popUpheight);
        enablePopUpView();
        setTabLayout();
        checkKeyboardHeight(parentLayout);
        enableFooterView();
    }

    public void setCurrentTabFragment(int position) throws IllegalAccessException, InstantiationException {
        String tag="";
        Fragment fr = null;
        Class frClass = null;
        FragmentManager frManager = getSupportFragmentManager();
        switch (position) {
            case 0:
                tag = "first";
                //hide
                if(frManager.findFragmentByTag("second")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("second")).commit();
                }
                if(frManager.findFragmentByTag("third")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("third")).commit();
                }
                if(frManager.findFragmentByTag("fourth")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("fourth")).commit();
                }

                //show
                if(frManager.findFragmentByTag("first")!=null){
                    frManager.beginTransaction().show(frManager.findFragmentByTag("first")).commit();
                }else{  //add
                    try {
                        frManager.beginTransaction().add(frameLayout.getId(), ((Fragment) Fragment_zasin.class.newInstance()), tag).commit();
                    }catch(Exception e){
                        Log.e("why", e.getMessage().toString());
                    }
                }
                break;
            case 1:
                tag = "second";
                //hide
                if(frManager.findFragmentByTag("first")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("first")).commit();
                }
                if(frManager.findFragmentByTag("third")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("third")).commit();
                }
                if(frManager.findFragmentByTag("fourth")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("fourth")).commit();
                }

                //show
                if(frManager.findFragmentByTag("second")!=null){
                    frManager.beginTransaction().show(frManager.findFragmentByTag("second")).commit();
                }else{  //add
                frManager.beginTransaction().add(frameLayout.getId(), ((Fragment) Fragment_zasin.class.newInstance()), tag).commit();
                }
                break;
            case 2:
                tag = "third";
                //hide
                if(frManager.findFragmentByTag("first")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("first")).commit();
                }
                if(frManager.findFragmentByTag("second")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("second")).commit();
                }
                if(frManager.findFragmentByTag("fourth")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("fourth")).commit();
                }

                //show
                if(frManager.findFragmentByTag("third")!=null){
                    frManager.beginTransaction().show(frManager.findFragmentByTag("third")).commit();
                }else{  //add
                    frManager.beginTransaction().add(frameLayout.getId(), ((Fragment) Fragment_zasin.class.newInstance()), tag).commit();
                }
                break;
            case 3:
                tag = "fourth";
                //hide
                if(frManager.findFragmentByTag("first")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("first")).commit();
                }
                if(frManager.findFragmentByTag("second")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("second")).commit();
                }
                if(frManager.findFramentByTag("third")!=null){
                    frManager.beginTransaction().hide(frManager.findFragmentByTag("third")).commit();
                }

                //show
                if(frManager.findFragmentByTag("fourth")!=null){
                    frManager.beginTransaction().show(frManager.findFragmentByTag("fourth")).commit();
                }else{  //add
                    frManager.beginTransaction().add(R.id.frame_layout, ((Fragment) Fragment_zasin.class.newInstance()), tag).commit();
                }
                break;
        }
        //frManager.beginTransaction().replace(R.id.frame_container, fr, tag).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }

    private void setTabLayout(){
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                try {
                    setCurrentTabFragment(tab.getPosition());
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void enablePopUpView() {

       //Creating a pop window for emoticons keyboard
        popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT,
                (int) keyboardHeight, false);

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                placesCoverLayout.setVisibility(LinearLayout.GONE);
            }
        });
    }

    int previousHeightDiffrence = 0;
    private void checkKeyboardHeight(final View parentLayout) {

        parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        parentLayout.getWindowVisibleDisplayFrame(r);

                        int screenHeight = parentLayout.getRootView()
                                .getHeight();
                        minusVal=screenHeight-r.bottom;
                        int heightDifference = screenHeight - (r.bottom+(minusVal));

                        if (previousHeightDiffrence - heightDifference > 50) {
                            popupWindow.dismiss();
                        }

                        previousHeightDiffrence = heightDifference;
                        if (heightDifference > 100) {

                            isKeyBoardVisible = true;
                            changeKeyboardHeight(heightDifference);

                        } else {

                            isKeyBoardVisible = false;

                        }

                    }
                });
    }

    private void changeKeyboardHeight(int height) {

        if (height > 100) {
            keyboardHeight = height;
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, keyboardHeight);
            placesCoverLayout.setLayoutParams(params);
        }

    }

    private void enableFooterView() {
        edtSearchPlaces.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });

        btnSearchPlaces.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hideSoftKeyboard(WriteRouteActivity.this);
                if(!popupWindow.isShowing()){
                    popupWindow.setHeight((int) (keyboardHeight));

                    if (isKeyBoardVisible) {
                        placesCoverLayout.setVisibility(LinearLayout.GONE);
                    } else {
                        placesCoverLayout.setVisibility(LinearLayout.VISIBLE);

                    }
                    popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
                    popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                    popupWindow.showAtLocation(parentLayout, Gravity.BOTTOM, 0, 0);

                    try {
                        setCurrentTabFragment(0);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    }

                } else {
                    //popupWindow.dismiss();
                }

            }
        });
    }

    @Override
    protected void onDestroy() {
        popupWindow.dismiss();
        super.onDestroy();
    }


    public static void hideSoftKeyboard(Activity activity) {
        InputMethodManager inputMethodManager =
                (InputMethodManager) activity.getSystemService(
                        Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), 0);
    }

    @Override
    public void onBackPressed() {
        if(popupWindow.isShowing()){
            popupWindow.dismiss();
        }else {
            super.onBackPressed();
        }
    }
}

activity_write_wroute.xml



    

    


    

    

Fragment_Zasin

public class Fragment_zasin  extends Fragment {
    public Fragment_zasin newInstance() {
        Fragment_zasin fr = new Fragment_zasin();
        return fr;
    }

    public Fragment_zasin() {

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_zasin, container, false);
        return rootView;
    }
}

places_popup.xml -ga o'ting



    

        

        

        

        

        

    


    


LOGCAT xabari

FAVQULODAN BO'LISh: Asosiy jarayonlar: suacuration.itgotravel, PID: 20131       java.lang.IllegalArgumentException: Id uchun 0x7f100173 fragmenti uchun hech qanday ko'rinish mavjud emas Fragment_zasin {d4ac39c # 0 id = 0x7f100173 birinchi}

Kimdir bunga yordam berishi mumkinmi?

0
@curiousMind um fragment_zasin.xml ichida hech narsa yo'q. android bilan faqat matnli ko'rinishi: text = "hello"
qo'shib qo'ydi muallif The Dongster, manba
Iltimos, xml formatini, fragment_zasin-ni joylashtiring
qo'shib qo'ydi muallif curiousMind, manba

6 javoblar

OK, men javob topdim. Muammo shundaki, fragment "Dialog" ning bolasi bo'la olmaydi. Men popup dialogini ishlatganimdan beri, suhbatdagilarning qismlarini qo'yisholmadi.

men tablayoutda bo'laklarni ishlatishdan ko'ra fikrlarni shaffoflashtirish bilan hal qildim.

1
qo'shib qo'ydi

Fragman menejeri fragmentni shamollash uchun kerak bo'lgan ko'rinishni topa olmasligi sababli, bu xato bo'ladi.

Fragmanli operatsiya faoliyat bilan bog'langan, shuning uchun bu xato paydo bo'lganda, ramka tartibi ushbu asosiy faoliyatning xml.so qismi bo'lmagani sababli, fragment.fragmentni qanday faoliyatga qo'shish kerakligini topa olmaydi.

Siz nima qilishingiz kerakligi sizning asosiy faoliyatingizdagi idorani taqdim etishdir. Masalan, sizning asosiy fikringiz











 

Fragmanni shamollatishga harakat qilayotgan ko'rinish faollik ichida bo'lishi kerak. Endi urinib ko'ring

frManager.beginTransaction().add(R.id.mainView, ((Fragment) Fragment_zasin.class.newInstance()), tag).commit();

fragment sizning faoliyatingizning ushbu ko'rinishiga yuklanadi.

1
qo'shib qo'ydi
Buni allaqachon sinab ko'rdim va bir xil xato yuz berdi va logcat xato xabari bir xil.
qo'shib qo'ydi muallif The Dongster, manba
Logcat orqali tekshirganimda, bu ikkita identifikator bir xil va ular NULL emas. Biroq fram_layout -dan joylar_popup.xml-dan boshlab, menimcha, "frame_layout" ning ushbu faoliyatdan foydalanish uchun usul bo'lishi kerak. lekin buni qanday qilishni bilmayman ..
qo'shib qo'ydi muallif The Dongster, manba
tushunmayman. bu "asosiy tartibda tartib uchun ishni boshlash" degani nimani anglatadi?
qo'shib qo'ydi muallif The Dongster, manba
Asosiy maketning ichida tartib uchun tranzaksiya boshlashingiz kerak.
qo'shib qo'ydi muallif Arpan Sharma, manba
Tahrirlashni tekshiring
qo'shib qo'ydi muallif Arpan Sharma, manba

Ushbu xatolik yuz berdi, chunki ID 0x7f100173 uchun fikringizni Fragment_zasin fragmani uchun topdik , shuning uchun faqat echim:

1) identifikatorning barcha identifikatorlarini ushbu tartibga tekshiring.

2) agar barcha identifikator ushbu tartibda mavjud bo'lsa va siz hali ham bir xil masalaga duch kelsangiz, bir narsa id nomi o'zgartirilmaydi va refactor nomini o'zgartirmang va o'zingizning fragmentingizda yoki faoliyatingizda ushbu o'zgartirilgan ismga kiring.

0
qo'shib qo'ydi

Muammo siz onCreate() saytida belgilangan tartibda aniqlanmagan view Fragment ni ko'rsatishga harakat qilyapsiz setContentView (layoutId)

Siz o'zingizning WriteRouteActivity qismidagi shablonlarni shitirlashingiz mumkin, unda tartibni aniqlaydigan activity_write_route va FrameLayout saytiga qo'shilgan qismlar places_popup. xml , shuning uchun framelayout ni Activity faoliyati ko'rinishida belgilang.

Kichik kirish:

--------code------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-------layout define for activity-------
setContentView(R.layout.activity_write_route);
}

Endi FrameLayout (view) da fragment qo'shilasiz

frManager.beginTransaction().add(R.id.frame_layout, ((Fragment) Fragment_zasin.class.newInstance()), tag).commit();

bu erda R.id.frame_layout sizning tartibingizda activity_write_route .

0
qo'shib qo'ydi
ko'proq narsani tushuntira olasizmi? Men ushbu qismni "Faoliyatning kontent ko'rinishida"
qo'shib qo'ydi muallif The Dongster, manba
hech qanday alternativa yo'qmi? nima uchun kvadrat maketini ko'rinishdan ochish ishlamaydi? juda qiziq
qo'shib qo'ydi muallif The Dongster, manba

Boshqa xatolar bo'lishi mumkin, ammo bu nima?

tb = (Toolbar) findViewById(R.id.nav_toolbar);

Bu asboblar paneli emas:


Ushbu nav_toolbar tartibida ko'rish mumkinmi?

Bundan tashqari, bu erda: "R.layout.fragment_zasin". Bu shunchaki shikoyat qiladi, shuning uchun bu yaxshi yoki yo'qligini ko'rib chiqaylik.

Yaxshiyamki, umumiy muammolarni bartaraf etish strategiyasi sifatida, initView() usulidagi barcha satrlarni sharhlab chiqing va ularni bajarilmaguniga qadar ularni bitta-bitta qo'shishingiz mumkin. Yoki xato jurnallarida pastga aylantirsangiz, u sizga xatoga yo'l qo'yadigan qatorga ko'prik beradi.

Nima uchun bir qatorda "frameLayout.getId ()" mavjud, biroq "R.id.frame_layout" boshqa sahifada? Barcha chiziqlar uchun ikkinchisini ishlatishga harakat qiling va buni tekshirib ko'ring.

0
qo'shib qo'ydi
u tagidagi yorliqni ishlatib asboblar panelini o'z ichiga oladi.
qo'shib qo'ydi muallif Raghunandan, manba
Ha, bu to'g'ri. asboblar panelini e'tiborsiz qoldiring. Android Studio'dan mening kodimni kopyaladım. bu tartib yaxshi ishlaydi ...
qo'shib qo'ydi muallif The Dongster, manba
Afsuski, bu ko'prik ko'rinmaydi. Ushbu strategiyani sinab ko'rganimda, bu "frManager.beginTransaction (). (Qo'shish) (Fragment_zasin.class.newInstance ()), tag) .commit (); " (?) "framelayout.getid ()" yoki "R.id.frame_layout" ko'rinishini topa olmaydi.
qo'shib qo'ydi muallif The Dongster, manba
Nima uchun bir qatorda "frameLayout.getId ()" mavjud, biroq "R.id.frame_layout" boshqa sahifada? Barcha chiziqlar uchun ikkinchisini ishlatishga harakat qiling va buni tekshirib ko'ring.
qo'shib qo'ydi muallif Michael Vescovo, manba

Men noto'g'ri faoliyat turini kengaytirmoqdaman, AppCompact-ni hal qildim.

0
qo'shib qo'ydi