2013-06-18 3 views
5

में टेक्स्टव्यू की एक चर संख्या बनाने के लिए कैसे उम्मीद है कि यह एक बुरा सवाल नहीं है, हालांकि मैंने एसओ के माध्यम से खोज की है। और जवाब खोजने में सक्षम नहीं हैं।एंड्रॉइड

मैं एक एंड्रॉइड एप्लिकेशन बना रहा हूं जो अनिवार्य रूप से अलार्म घड़ी है। मैं मुख्य गतिविधि अलार्म के बारे में कुछ जानकारी के साथ बनाए गए सभी अलार्म प्रदर्शित करना चाहता हूं। इस बारे में मेरा सवाल यह है कि कितने अलार्म बनाए गए हैं, इस पर आधारित टेक्स्ट दृश्यों की एक विस्तृत संख्या कैसे बनाएं। उदाहरण के लिए यदि उपयोगकर्ता ने 5 अलार्म बनाए हैं (और हटाए नहीं हैं), तो मैं इसे टेक्स्ट दृश्यों की हार्ड-कोडित संख्या के बजाय 5 टेक्स्टव्यू कैसे प्रदर्शित करूं? कार्यक्षमता का परीक्षण करने के लिए मेरे बेहद कठोर कोडित प्रोटोटाइप निम्नलिखित हैं (इस hangup के अलावा)।

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Launch" > 

    <ScrollView 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <LinearLayout android:orientation="vertical" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent"> 

      <TextView 
       android:orientation = "vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="75dp" 
       android:text="Time"/> 
        <View 
        android:layout_width="fill_parent" 
        android:layout_height="0.2dp" 
        android:id="@+id/separator" 
        android:visibility="visible" 
        android:background="@android:color/darker_gray"/> 

      <TextView 
       android:orientation = "vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="75dp" 
       android:text="Time"/> 
        <View 
        android:layout_width="fill_parent" 
        android:layout_height="0.2dp" 
        android:id="@+id/separator" 
        android:visibility="visible" 
        android:background="@android:color/darker_gray"/> 

      <TextView 
       android:orientation = "vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="75dp" 
       android:text="Time"/> 
        <View 
        android:layout_width="fill_parent" 
        android:layout_height="0.2dp" 
        android:id="@+id/separator" 
        android:visibility="visible" 
        android:background="@android:color/darker_gray"/> 


     </LinearLayout> 

    </ScrollView> 


</RelativeLayout> 

जैसा कि आप देख सकते हैं, वहाँ उपयोगकर्ता द्वारा बनाई गई के रूप में पाठ विचारों की एक संख्या सिर्फ तीन हार्ड-कोडेड पाठ विचारों के बजाय कर रहे हैं।

फिर से, मुझे आशा है कि यह किसी प्रश्न की गहराई में भी नहीं है या जिस पर उत्तर कहीं और पोस्ट किया गया है लेकिन मैंने इसकी खोज की और कुछ भी नहीं मिला।

अग्रिम धन्यवाद!

+0

तुम बस नहीं एक्सएमएल के माध्यम से प्रोग्राम के ऐसा करने के लिए, की आवश्यकता होगी। –

+0

आप स्क्रॉलव्यू के बजाय उस सूचीदृश्य और कर्सरैडाप्टर का उपयोग कर सकते हैं। मेरा मतलब है कि यदि आप डीबी में अलार्म सहेजते हैं तो आप प्रदर्शन अलार्म –

+0

के लिए कर्सरैडाप्टर के साथ एक सूचीदृश्य का उपयोग कर सकते हैं देखें कि मेरा जवाब आपकी मदद करता है या नहीं। चूंकि आप SO के लिए नए हैं, इसलिए [टूर] देखें (http://stackoverflow.com/about)। –

उत्तर

4

आप इस प्रोग्राम के रूप में कर सकते हैं:

int size = numAlarms; // total number of TextViews to add 

TextView[] tv = new TextView[size]; 
TextView temp; 

for (int i = 0; i < size; i++) 
{ 
    temp = new TextView(this); 

    temp.setText("Alarm: " + i); //arbitrary task 

    // add the textview to the linearlayout 
    myLinearLayout.addView(temp); 

    tv[i] = temp; 
} 
+0

तो बस यह सुनिश्चित करने के लिए कि मैं आपके द्वारा सुझाए गए प्रोग्रामेटिक समाधान का उपयोग करने में सही ढंग से समझ रहा हूं, मुझे कोड में पहले से ही रैखिक लेआउट प्रोग्रामेटिक रूप से जोड़ने की आवश्यकता होगी, या क्या मैं इसे किसी XML संदर्भ में जोड़ सकता हूं? या मुझे लगता है कि मैं बस अपने एक्सएमएल रैखिक लेआउट को पुनः प्राप्त कर सकता हूं: 'LinearLayout linearLayout = (LinearLayout) findViewById (R.id.IdToBeSetInXml);' –

+0

हां, आप यह कर सकते हैं। –