2017-06-19 16 views
5

Tôi đang cố gắng tự động điền chế độ xem danh sách có thể mở rộng của mình bên trong Android Studio bằng Kotlin. Nhưng hiện tại, tôi không thể tìm thấy bất kỳ chức năng cập nhật nào để làm như vậy, tất cả các chức năng mà tôi thấy dường như đã lỗi thời. Đây là mã bộ xương của tôi:Kotlin - Thêm các mục vào ExpandableListView

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 
    } 

Cảm ơn trước

+1

Google "ExpandableListView dụ" và bạn sẽ có thể tìm nó ra. – rozina

+0

yep, tôi tìm thấy hàm setAdapter. Chỉ có vẻ khó khăn khi tạo ra một ExpandableListAdapter. Tôi chỉ quản lý để có được một ArrayAdapter làm việc, mà không giúp tôi nhiều. – OhMad

Trả lời

0

Đối với tôi nó làm việc tốt.
Trong hoạt động của bạn nơi bạn xác định listdata bạn làm điều này:

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

Đây là nhà xây dựng trong danh sách bộ chuyển đổi mở rộng của tôi

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; 
} 
... 
Các vấn đề liên quan