2017-06-19 52 views
5

Android Studio'nun genişletilebilir liste görünümünü dinamik olarak Kotlin kullanarak dinamik olarak yerleştirmeye çalışıyorum. Ama şu andan itibaren, herhangi bir güncel fonksiyon bulmayı başaramadım, bulduğum tüm fonksiyonlar modası geçmiş gibi görünüyor. Benim için peşinKotlin - ExpandableListView'e öğe ekle

+1

tarihinde "ExpandableListView örneği" de yapıcı ve bunu anlamaya mümkün olmalıdır: Eğer listData tanımlamak etkinlik olarak
bunu. – rozina

+0

Evet, setAdapter işlevini buldum. Sadece bir ExpandableListAdapter oluşturma mücadelesi gibi görünüyor. Sadece bir ArrayAdapter çalışmamı başardım, bu da bana fazla yardımcı olmuyor. – OhMad

cevap

0

yılında

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 
    } 

sayesinde iyi çalıştı: Bu benim iskelet kodudur.

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); 

Bu benim genişletilebilir liste adaptörü

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; 
} 
...