2012-01-10 54 views
-2

雖然我編程有關語音識別的android程序我有一個小問題。什麼是r.id無法解決我已嘗試更改我的XML文件,其中包括res folder.it不工作,我該怎麼辦?r.id id無法解析

我的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" > 

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

</LinearLayout> 
+0

我們不介意讀者你的代碼是什麼樣子,張貼一些代碼。 – JPM 2012-01-11 18:06:38

回答

0

插入這對XML文件的視圖標籤。

機器人:ID = 「@ + ID/YOUR_VIEW_ID

1

嘗試清潔您的項目(在Eclipse中:項目 - >清除...)。 如果不能解決它,請刪除位於gen文件夾下的R.java文件。 R.java文件應該爲您重新生成。 我已經做了這些事情來解決你所描述的問題,但是你的里程可能會有所不同。

1

如果某處在您的類文件,你有這樣的一行:

TextView tv = (TextView) findViewById(R.id.tv1); 

然後R.id.tv1必須指向你的XML,一個TextView必須首先給出的ID。因此,舉例來說,如果你想改變文本在你的TextView上面你會是這樣的設定在XML中的ID:

<?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" > 

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

    //Set your id here: 
    android:id="@+id/TEXTVIEW1" 
/> 

,然後更改文本,在你的類,你'有這樣的:

TextView tv = (TextView) findViewById(R.id.TEXTVIEW1); 
tv.setText("How are you");