2

私はエキスパンドリストビューを使用しています。 すべてがうまくいきます。 ボタンを追加したので、idでfindviewできません。 MainActivityの.java:カスタムリストビューがボタンを見つけることができません

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)が再生成され、クラスで使用できるようになります。 (ビルド - >クリーンプロジェクトとビルド - プロジェクトの再構築)

関連する問題