2

확장 가능한 listView를 사용하고 있습니다. 모든 것이 정상적으로 작동하고 있습니다. 그러나 단추를 추가 했으므로 ID로 findview를 찾을 수 없습니다. MainActivity 된 .java :사용자 지정 ListView에서 단추를 찾을 수 없습니다.

public class MainActivity extends Activity { 

    Button btn; 
    ExpandableListAdapter listAdapter; 
    ExpandableListView expListView; 
    List<String> listDataHeader; 
    HashMap<String, List<String>> listDataChild; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     // get the listview 
     btn=(Button)findViewById(R.id.button); //Cannot Resolve symbol "button" 
     expListView = (ExpandableListView) findViewById(R.id.lvExp); 

     // preparing list data 
     prepareListData(); 

     listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); 

     // setting list adapter 
     expListView.setAdapter(listAdapter); 

    } 
} 

어떤 오류 일 수 있습니다 :? activity_main.xml는 :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.lvexpandable.MainActivity"> 

    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:orientation="vertical" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent"> 

     <ExpandableListView 
      android:id="@+id/lvExp" 
      android:layout_width="match_parent" 
      android:layout_height="450dp" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="230dp" 
      android:text="Button" 
      tools:layout_editor_absoluteX="257dp" 
      tools:layout_editor_absoluteY="360dp" /> 
    </LinearLayout> 

</android.support.constraint.ConstraintLayout> 

확장의 ListView는 잘 작동하지만 버튼도 EX LV와 같은 XML에있는 인식되지 않습니다.

+0

정확한 오류 메시지는 무엇입니까? – leoderprofi

+0

점검 사항 업데이트 됨 –

답변

1

프로젝트를 정리하고 다시 작성하려고 했습니까? 이렇게하면 모든 리소스 (R.java)가 다시 생성되어 클래스에서 사용할 수 있습니다. (빌드 -> 프로젝트 정리 및 빌드 - 프로젝트 재건)

관련 문제