- Forum-Beiträge: 180
14.01.2015, 10:58:24 via Website
14.01.2015 10:58:24 via Website
Hei Leute ich habe gerade in einem Fragment einen kompletten Adapter für eine Expandable List View gemacht und er weist auch keine Fehler auf.
Jedoch wenn ich den Adapter der Expandable ListView zuweisen will.
Hier der Fehler:
Also es findet die Zuweisungen nicht...
Hier der ganze Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
namespace HKEDV_GPS
{
public class LocationBookFragment : Fragment
{
public static Fragment NewInstance(int position)
{
Fragment fragment2 = new LocationBookFragment();
Bundle args = new Bundle();
return fragment2;
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.Inflate (Resource.Layout.locationbook, container, false);
var list1 = View.FindViewById<ExpandableListView> (Resource.Id.expandableListView1);
list1.SetAdapter (new ExpendListAdapter (Activity, _dictGroup));
list1.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e) {
var itmGroup = lstKeys [e.GroupPosition];
var itmChild = _dictGroup [itmGroup] [e.ChildPosition];
Toast.MakeText (Activity, string.Format ("You Click on Group {0} with child {1}", itmGroup, itmChild),
ToastLength.Long).Show ();
};
}
public class ExpendListAdapter: BaseExpandableListAdapter
{
Dictionary<string, List<string>> _dictGroup =null;
List<string> _lstGroupID = null;
Activity _activity;
private readonly Context _context;
public ExpendListAdapter (Activity activity,
Dictionary<string, List<string>> dictGroup)
{
_dictGroup = dictGroup;
_activity = activity;
_lstGroupID = dictGroup.Keys.ToList();
}
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
var item = _lstGroupID [groupPosition];
if (convertView == null)
convertView = _activity.LayoutInflater.Inflate (Android.Resource.Layout.SimpleListItem1, null);
return convertView;
}
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
var item = _dictGroup [_lstGroupID [groupPosition]] [childPosition];
if (convertView == null)
convertView = _activity.LayoutInflater.Inflate (Android.Resource.Layout.SimpleListItem1, null);
return convertView;
}
public override Java.Lang.Object GetChild (int groupPosition, int childPosition)
{
throw new NotImplementedException ();
}
public override long GetChildId (int groupPosition, int childPosition)
{
throw new NotImplementedException ();
}
public override int GetChildrenCount (int groupPosition)
{
throw new NotImplementedException ();
}
public override Java.Lang.Object GetGroup (int groupPosition)
{
return _lstGroupID [groupPosition];
}
public override long GetGroupId (int groupPosition)
{
return groupPosition;
}
public override bool IsChildSelectable (int groupPosition, int childPosition)
{
throw new NotImplementedException ();
}
public override int GroupCount {
get {
return _dictGroup.Count;
}
}
public override bool HasStableIds {
get {
throw new NotImplementedException ();
}
}
void CreateExpendableListData ()
{
for (int iGroup = 1; iGroup <= 3; iGroup++) {
var lstChild = new List<string> ();
for (int iChild = 1; iChild <= 3; iChild++) {
lstChild.Add (string.Format ("Group {0} Child {1}", iGroup, iChild));
}
_dictGroup.Add (string.Format ("Group {0}", iGroup), lstChild);
}
var lstKeys = new List<string>(_dictGroup.Keys);
}
}
}
}
Hoffe jemand kann helfen!
MFG Lukas R.
Programmieren ist nicht nur eine Wissenschaft, sondern auch ein Lifestyle!
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.