2013-02-13 3 views
0

희망하는 것은 간단합니다.EditText XML 참조 문제

나는 여기서 해결할 수없는 매우 간단한 문제가 있습니다. 나는 단순히 XML 레이아웃의 EditText를 findViewById 등의 코드를 사용하여 코드에 참조하려고 시도하고있다. 어떤 이유로 든 프로젝트를 정리하고 내 R 리소스 파일을 다시 생성하고 ctrl + o를 사용하여 가져 오기를 확인했다. 나는 이클립스가 XML 레이아웃의 EditText에 대한 링크를 '보게'할 수 없다.

누군가가이 좌절적이고 간단한 오류로 나를 도울 수 있기를 바랍니다.

현재 오류 :

totalListPrice cannot be resolved or is not a field 

이 totalListPrice '기준으로 사용되는 간단한 코드; 내 코드에서 글고 내 XML에 :

totalPrice = (EditText)findViewById(android.R.id.totalListPrice); 

그리고 이것은 내 XML 레이아웃입니다 (문제가 글고이 표시되었습니다) :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="84dp" 
    android:orientation="horizontal" 
    android:focusableInTouchMode="false"> 

    <ImageView 
     android:id="@+id/imgLink" 
     android:layout_width="78dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:src="@drawable/viewcon" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="75dp" 
     android:gravity="center" 
     android:text="Shopping List" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textSize="35sp" 
     android:focusableInTouchMode="false" 
     android:clickable="false" 
     android:focusable="false" /> 
</LinearLayout> 

<TextView 
    android:id="@+id/txtItemDes" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:text="Search From An Item In The List:" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<EditText 
    android:id="@+id/inputAppointName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="Enter An Item Name" > 

    <requestFocus /> 
</EditText> 

<Button 
    android:id="@+id/btnAddItem" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Add"/> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="56px" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/txtPrice" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Total Price:" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 
    *************ERROR************* 
    <EditText 
     android:id="@+id/totalListPrice" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:ems="10" 
     android:inputType="number"></EditText> 

</LinearLayout> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

</LinearLayout> 

답변

1

그것은 당신의 자바 파일 대신 안드로이드 프레임 워크의 R 클래스

import <your package name>.R; 
+0

많은 감사합니다 ....이

R.id.totalListPrice 

하지

android.R.id.totalListPrice 

가져 오기 현지 R 클래스해야한다 내 listview whicb 안드로이드 필요로보고 내 때문이었습니다. 많은 감사 – user1352057

+0

다음 번에'R' 클래스를 포함 할 때주의해야합니다. – Geros

+1

이것이 문제의 해결책이라면, 미래의 사용자를위한 대답으로 받아 들여야한다고 생각하십시오! – hwrdprkns

1

당신은 앞에 "안드로이드"를 필요가 없습니다 대신 자신의 패키지에서 생성 된 R 파일을 가져옵니다 (import android.R 행을 삭제하고 R 가져 오기로 쉽게 바꿀 수 있어야합니다).

그냥 R.id.totalListPrice이어야합니다.