亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復“無法將類型 BaseExpandableListAdapter 隱式轉換為

如何修復“無法將類型 BaseExpandableListAdapter 隱式轉換為

C#
一只萌萌小番薯 2023-04-29 15:49:35
我正在嘗試設置一個自定義可擴展列表視圖適配器(繼承自 BaseExpandableListAdapter)以用作 Xamarin.Android 中 ExpandableListView 小部件的適配器。我正在使用 Visual Studio 2019 和 Xamarin.Android v28.0.0.1根據這些網站的示例,我得到了一些我認為應該有效的東西。http://www.appliedcodelog.com/2016/06/expandablelistview-in-xamarin-android.html https://gist.github.com/lprichar/904ade6f1aaf96d172436bed3fb24d9b https://www.codeproject.com/Articles/677206/MonoAndroid-Writing-ExpandableListView-amdanswers_fragment.axml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="match_parent">    <ExpandableListView        android:minWidth="25px"        android:minHeight="25px"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/answers" /></LinearLayout>片段.cs    public class AnswersFragment : Fragment    {        private readonly Dictionary<string, bool> answers;        public AnswersFragment(Dictionary<string, bool> answers)        {            this.answers = answers;        }        // Display list of the questions and where answers matched.        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)        {            View view = inflater.Inflate(Resource.Layout.answers_fragment, container, false);            view.FindViewById<ExpandableListView>(Resource.Id.answers).Adapter = new AnswersListViewAdapter(Context, answers); // This is where the implicit type conversion error occurs            return view;        }    }
查看完整描述

1 回答

?
絕地無雙

TA貢獻1946條經驗 獲得超4個贊

為了便于理解,我們可以這樣定義變量:


  AnswersListViewAdapter listAdapter;

  ExpandableListView expListView;

并像這樣使用:


 public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

    {


        View view = inflater.Inflate(Resource.Layout.answers_fragment, container, false);

        expListView = view.FindViewById<ExpandableListView>(Resource.Id.answers);

        listAdapter = new AnswersListViewAdapter(Application.Context, answers); // This is where the implicit type conversion error occurs

        expListView.SetAdapter(listAdapter);


        //view.FindViewById<ExpandableListView>(Resource.Id.answers).Adapter = new AnswersListViewAdapter(Context, answers);


        return view;

    }

當然你也可以直接這樣使用:


 view.FindViewById<ExpandableListView>(Resource.Id.answers).SetAdapter(new AnswersListViewAdapter(Application.Context, answers));



查看完整回答
反對 回復 2023-04-29
  • 1 回答
  • 0 關注
  • 127 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號