मेरा ऐप सर्वेक्षण बनाने के बारे में है। ऐसा करने के लिए, उपयोगकर्ता को गतिशील रूप से नए फ़ील्ड बनाने में सक्षम होना चाहिए।एक बटन पर क्लिक किए जाने पर एक ही माता-पिता में कई बार एक दृश्य को घुमाएं
तो, जब कोई नया सर्वेक्षण बनाते हैं, तो गतिविधि केवल 2 बटन (जोड़ें और हटाएं) के साथ दिखायी जाती है। जब कोई उपयोगकर्ता ऐड बटन पर क्लिक करता है, तो एक पंक्ति में एक संपादन टेक्स्ट होता है (इसलिए वह प्रश्न लिख सकता है), एक स्पिनर (जो उपयोगकर्ता को फ़ील्ड के प्रकार का चयन करने में सक्षम बनाता है: टेक्स्ट, रेडियोबटन, चेकबॉक्स, आदि ..) और दूसरा एडिटटेक्स्ट (जिसमें लागू होने पर विभिन्न उपलब्ध उत्तर विकल्प लिखे गए हैं)।
इसे पूरा करने के लिए मैंने इन विजेट्स वाली एक एक्सएमएल फ़ाइल बनाई और प्रत्येक बार जब उपयोगकर्ता ऐड बटन में क्लिक करता है, तो एक्सएमएल फुलाया जाता है। यह पहली बार काम करता है जब मैं बटन दबाता हूं, लेकिन उसके बाद ... कुछ भी नहीं होता है।
मैंने कहीं पढ़ा है कि जब तक आप लूप में नहीं किया जाता है तब तक आप एक ही बच्चे को एक ही बच्चे को फुला नहीं सकते।
तो, मेरे सवाल कर रहे हैं:
-> मैं इस के आसपास मिलता है और वांछित प्रभाव को प्राप्त कर सकते हैं?
-> यह लूप में क्यों लागू नहीं होता है?
किसी भी मदद या संकेत की सराहना की जाती है। एक बार फिर, समुदाय ने मुझे जो समर्थन दिया है, उसके लिए आपको बहुत बहुत धन्यवाद।
नोट: एंड्रॉइड प्रलेखन में वे एक inflator cloning के बारे में बात करते हैं लेकिन जानकारी दुर्लभ है और मुझे इसके बारे में कोई अन्य जानकारी नहीं मिल सका।
स्रोत कोड:
एक्सएमएल - मुख्य cointainer:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/mds_new_addfield_button"
android:tag="new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Field"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/mds_new_deletefield_button"
android:tag="delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete Field"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
एक्सएमएल -Inflated:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:id="@+id/mdsnew_field_tv"
style="@style/dsn_field"
android:text="Field Name "
/>
<TextView
android:id="@+id/mdsnew_type_tv"
style="@style/dsn_field"
android:text="Type of Field "
/>
<TextView
android:id="@+id/mdsnew_choices_tv"
style="@style/dsn_field"
android:text="Choices"
/>
</TableRow>
<TableRow>
<EditText
android:id="@+id/mdsnew_fieldname_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Field Name"
android:textSize="18sp"
/>
<Spinner
android:id="@+id/mdsnew_type_sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/mdsnew_choices_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choices "
android:textSize="18sp"
/>
</TableRow>
</TableLayout>
बटन जोड़ें:
LinearLayout myRoot = (LinearLayout) findViewById(R.id.wrapper);
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.mds_new_row, myRoot);
आप एक ही बच्चे को दो या अधिक बार फुला सकते हैं। आप एक बार एक से अधिक दृश्यों का एक ही उदाहरण उपयोग करने के लिए क्या नहीं कर सकते हैं। प्रत्येक बार जब आप 'लेआउट इनफ्लेटर' की 'inflate' विधि' कहते हैं तो आप एक नया 'व्यू' बना रहे हैं, इसलिए आपको चीजों को करने के तरीके में समस्या नहीं होनी चाहिए। तो ... त्रुटि कहीं और हो सकती है ... क्या आप कृपया एक्सएमएल फाइलों को साझा कर सकते हैं (कंटेनर और रनटाइम में जो एक है)? साथ ही, कोड का स्निपेट जहां आप अपना दृश्य बढ़ाते हैं, सहायक होगा। – Cristian
आपने जो भी पूछा है उसे शामिल करने के लिए पोस्ट को संपादित किया! (आपकी मदद के लिए धन्यवाद!) – Tivie
आप प्रत्येक दृश्य के लिए आईडी कैसे पुनर्प्राप्त करेंगे। – Janmejoy