के साथ बनाए गए दृश्य में गतिशील रूप से तत्व कैसे जोड़ूं I XML के साथ बनाए गए दृश्य में गतिशील सामग्री जोड़ने की कोशिश कर रहा हूं।मैं XML
मेरे पास एक "प्रोफ़ाइल_सूची" है जिसमें स्क्रॉलव्यू है जिसमें मैं कुछ तत्व जोड़ना चाहता हूं।
यहां कुछ कोड है जो मैं करने की कोशिश कर रहा हूं।
// Find the ScrollView
ScrollView sv = (ScrollView) this.findViewById(R.id.scrollView1);
// Create a LinearLayout element
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
// Add text
tv = new TextView(this);
tv.setText("my text");
ll.addView(tv);
// Add the LinearLayout element to the ScrollView
sv.addView(ll);
// Display the view
setContentView(R.layout.profile_list);
योजना एक TableLayout जोड़ सकते हैं और गतिशील रूप से और न केवल एक डमी पाठ भरने के लिए है, लेकिन पहले मैं यह काम करने के लिए मिल जाना चाहिए।
किसी भी मदद का स्वागत है।
सधन्यवाद Olle
मैं समाधान मिल गया!
बेवकूफ मुझे मैंने अपने XML-file में अपने स्क्रॉलव्यू में एक तत्व छोड़ा था!
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.profile_list, null);
// Find the ScrollView
ScrollView sv = (ScrollView) v.findViewById(R.id.scrollView1);
// Create a LinearLayout element
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
// Add text
TextView tv = new TextView(this);
tv.setText("my text");
ll.addView(tv);
// Add the LinearLayout element to the ScrollView
sv.addView(ll);
// Display the view
setContentView(v);
और एक्सएमएल फ़ाइल
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:id="@+id/scrollView1"
android:clickable="true"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_marginBottom="50px"
android:layout_height="fill_parent">
</ScrollView>
</LinearLayout>
आशा इस कोई मदद मिलेगी मिलान करने के लिए:
वैसे भी उसके एक काम उदाहरण है। सभी मदद के लिए धन्यवाद!
मैं चुपचाप समझ नहीं पा रहा हूं कि आप क्या करना चाहते हैं। कस्टम दृश्य बनाने के बारे में कैसे ??? मुझे लगता है कि यह बेहतर है – Hein
कस्टम दृश्य से आपका मतलब गतिशील रूप से संपूर्ण दृश्य बनाना है? अगर मैं एक बेवकूफ सवाल पूछता हूं तो मैं उससे बहुत नया हूं इसलिए मुझे माफ़ कर दो। मैंने कोशिश की लेकिन मुझे इस तरह काम करने के लिए डिज़ाइन और लेआउट नहीं मिला, इसलिए मैंने पूरी शुरुआत की। – Olle