العودة إلى موقع برمج

How can i change the itemLayout in Adapter class

android
#1

I try to get a key from the main class but it is Always getting null

```
 Bundle bundle =new Bundle();
 String type = bundle.getString("theType");



if (type =="Check"){

    view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.item_note_check, parent, false);

}else if (type =="photo"){
    view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.item_note_photo, parent, false);
}else {view = LayoutInflater.from(parent.getContext())
         .inflate(R.layout.item_note, parent, false);
}المحافظة على التنسيق
```

to get kType from

public void onRadioButtonTypeClicked(View view) {
    // Is the button now checked?
    boolean checked = ((RadioButton) view).isChecked();
Bundle bundle = new Bundle();

   // Intent intent = new Intent();
    kType="photo";
    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.radioButtonSheet:
            if (checked)
                mImageNoteV.setImageResource(R.drawable.radio_button_note);
            kType= "note";
            bundle.putString("theType",kType);
         //   intent.putExtra("theType",kType);
            break;
        case R.id.radioButtonDone:
            if (checked)
                mImageNoteV.setImageResource(R.drawable.radio_button_check_box);
            kType="Check";
            bundle.putString("theType",kType);
        //   intent.putExtra("theType",kType);
            break;
        case R.id.radioButtonPicture:
            if (checked)
                mImageNoteV.setImageResource(R.drawable.radio_button_photo);
            kType = "photo";
            bundle.putString("theType",kType);
         //   intent.putExtra("theType",kType);
            break;
    }

i try to set it in other class and get it again from it but does not work = null. is there good way to solve this

https://stackoverflow.com/questions/60236931/how-can-i-change-the-itemlayout-in-adapter-class/60238047?noredirect=1#comment106553915_60238047<
ارجو الاجابة بالعربي

#2

يمكنك محاولة تغيير الكود لديك الى

Bundle bundle = getIntent().getExtras();

//Extract the data…
String venName = bundle.getString("theType");        

//Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(venName);

وبذلك يمكنك التحقق من وجود هذا الkey ضمن الفعالية الثانية لديك في اي وقت مثل هذا المثال

if (bundle.containsKey(MainActivity.theType))    {
    ....
}

;كما هو موضح ضمن الرابط التالي

#3

ما اقدر استدعي getIntent
image

#4

ماهي رسالة الخطأ الظاهرة عند تشغيل البرنامج

#5

تم حل الموضوع هنا

1 Like