2012-02-06 12 views
6

इम बहुत ही इस एंड्रॉयड development.I सिर्फ एक हैलो दुनिया आवेदन बनाने के लिए शुरू कर दिया करने के लिए नए में एक पृष्ठभूमि छवि स्थापित करने के लिए।कैसे एंड्रॉयड

मैं एक पृष्ठभूमि छवि स्थापित करने के लिए करने की कोशिश की और यह काम कर रहा है fine.When मैं छवि यह काम नहीं कर रहा है पर एक पाठ जोड़ने की कोशिश की।

मैं रास्ते में करने की कोशिश की below.Can किसी कृपया मेरी मदद जहां im गलत हो रहा।

Main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/andriod" 
    android:layout_gravity="center_vertical" 
    android:gravity="center_vertical"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

</LinearLayout> 

HelloActivity.java

import android.app.Activity; 
    import android.os.Bundle; 
    import android.widget.TextView; 
    //import android.widget.ImageView;  

    public class HelloActivity extends Activity { 
    // /** Called when the activity is first created. */ 
    // @Override 
    // public void onCreate(Bundle savedInstanceState) { 
    //  super.onCreate(savedInstanceState); 
    //  setContentView(R.layout.main); 
    // }  

    /** Called when the activity is first created. */ 
     @Override 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      TextView tv = new TextView(this);    
      tv.setText("This is the first andorid app");   
      setContentView(R.layout.main);   
     } 
} 

जब चल रहा है यह पृष्ठभूमि छवि दिखा रहा है लेकिन नहीं दिखा रहा है "यह पहली Andorid अनुप्रयोग है" में

आपकी मदद के लिए आशा

+3

@ishhhh: आप TextView टीवी में पाठ सेट कर रहे हैं, लेकिन लेआउट में इस टीवी को जोड़ने नहीं। – Mudassir

उत्तर

3

आप अपनी अनूठी आईडी के साथ अपने लेआउट फ़ाइल में TextView का चयन करना होगा और फिर इसे गुण सेट करें। लेकिन आपके कोड में, आप बस पाठ के साथ एक टेक्स्ट व्यू बनाते हैं और इसे दृश्य में नहीं रखते हैं।

TextView tv = (TextView) findViewById(R.id.textView1); 
tv.setText("Your text here"); 
+0

धन्यवाद बहुत दोस्त.मैंने मेरे लिए काम किया – ishhhh

+0

क्या आप कृपया मुझे बता सकते हैं कि मैं एसडीके में डाउनलोड की गई एंड्रॉइड नमूना परियोजनाओं को कैसे चला सकता हूं। जब मैं नमूना प्रोजेक्ट डाउनलोड करता हूं तो मैं इसे चलाने में सक्षम नहीं हूं। क्या आप कृपया मेरी मदद करें – ishhhh

+0

आपका स्वागत है। यदि आपके पास ग्रहण स्थापित है, एंड्रॉइड प्रोजेक्ट विज़ार्ड में, एक विकल्प है जिसे आप देखेंगे जो सीधे ग्रहण में नमूना परियोजनाएं खोलता है। – NotCamelCase

4

आप .. वर्तमान सामग्री देखने से TextView लाने के बाद setContentView (..), भी अपने पाठ को देखने के लिए एक आईडी जोड़ने के लेआउट में इन पंक्तियों को जोड़ने की आवश्यकता

TextView tv = (TextView)findViewById(...) 
+0

सहमत.निस जवाब। –

+0

thankyou rajdeep – ishhhh

6

सबसे पहले आप, इतना है कि यह जावा स्रोत (ध्यान दें एंड्रॉयड: निम्न XML में आईडी गुण) में पहुँचा जा सकता है TextView एक्सएमएल फ़ाइल में एक आईडी देने की आवश्यकता;

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/andriod" 
    android:layout_gravity="center_vertical" 
    android:gravity="center_vertical"> 

    <TextView 
     android:id="@+id/textView" 

     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

</LinearLayout> 

अब टेक्स्ट को इस टेक्स्टव्यू में सेट करें;

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TextView textView = (TextView) findViewId(R.id.textView); 

    textView.setText("This is the first andorid app"); 
} 

नोट, एक्सएमएल में घोषित टेक्स्टव्यू को यहां से कैसे पहुंचाया गया है।

यह

TextView textView = new TextView(this); 

यह एक नया TextView पैदा करेगा नहीं है। लेकिन क्या हम यहाँ की जरूरत है

TextView textView = (TextView) findViewId(R.id.textView); 

इस TextView ऊपर एक्सएमएल फ़ाइल में घोषित करने के लिए उल्लेख करते हैं।

+0

आपके विस्तृत स्पष्टीकरण के लिए धन्यवाद। यह मेरे जैसे शुरुआती लोगों के लिए बहुत उपयोगी है। भविष्य में आपकी मदद के लिए भी आशा करें – ishhhh

+0

@ishhhh: निश्चित रूप से, और उपवास के लिए धन्यवाद। – Mudassir

+0

: क्या आप मुझे बता मैं कैसे एसडीके में डाउनलोड एंड्रॉयड नमूना परियोजनाओं को चला सकते हैं कर सकते हैं।जब मैं नमूना प्रोजेक्ट डाउनलोड करता हूं तो मैं इसे चलाने में सक्षम नहीं हूं। कृपया मेरी मदद करें – ishhhh