2017-06-19 11 views
5

私は、Androidスタジオの中で、Kotlinを使用して、自分の展開可能なリストビューを動的に作成しようとしています。しかし、今のところ、私はそれを行うための最新の機能を見つけることができませんでした、私が見つけたすべての機能は古くなっているようです。私にとっては、事前Kotlin - ExpandableListViewに項目を追加する

+1

Googleの「ExpandableListView例」で、コンストラクタであり、あなたがそれを把握することができる必要があります:あなたはあなたのlistDataプロパティを定義し、あなたの活動で
は、これを行います。 – rozina

+0

うん、私はsetAdapter関数を見つけました。 ExpandableListAdapterの作成には苦労しているようです。私はArrayAdapterを動作させることしかできませんでしたが、それは私にはあまり役に立ちません。 – OhMad

答えて

0

private val shows = listOf("First", "Breaking Bad", "Game of Thrones", "Bob and Martin...") 

    private val expandableListView: ExpandableListView by bind(R.id.theListView) 

    override fun onCreate(savedInstanceState: Bundle?) { 
     super.onCreate(savedInstanceState) 
     setContentView(R.layout.activity_main) 

     //Add items to expandable list view here 
    } 

おかげで、それがうまく働いた:これは私のスケルトンコードです。

private ArrayList<HeaderInfo> SectionList = new ArrayList<>(); 
... 
//create the adapter by passing your ArrayList data 
listAdapter = new ExpandableListAdapter(MyListActivity.this, SectionList); 
//attach the adapter to the list 
expandableListView.setAdapter(listAdapter); 

これは私の拡張可能なリストアダプタ

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

private Context context; 
private ArrayList<HeaderInfo> SectionList; 

public ExpandableListAdapter(Context context, ArrayList<HeaderInfo> 
SectionList) { 
    this.context = context; 
    this.SectionList = SectionList; 
} 
... 
関連する問題