나는 동일한 활동에서 호출하는 AlertDialog의 활동에있는 ListAdapter를 새로 고치는 방법에 대해 꽤 난처한 입장입니다. 여기 ListAdapter를 대화 상자에서 새로 고침
는 활동의 코드입니다 :private static ArrayAdapter<CarProfile> mainListAdapter;
public class CarProfiles : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
mainListAdapter = new ArrayAdapter<CarProfile>(this, Android.Resource.Layout.SimpleListItem1, carProfiles);
// This targets a ListView in my axml with id list.
ListAdapter = mainListAdapter;
ShowCarProfileFormDialog(parameters blah, blah, blah);
}
}
그리고 이것은 내에 AlertDialog입니다 : 내 datasouce 문제없이 업데이트됩니다,
public class CarProfileDialogFragment : DialogFragment
{
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
LayoutInflater inflater = Activity.LayoutInflater;
View view = inflater.Inflate(Resource.Layout.CarProfileForm, null);
// component init (removed)
var builder = new AlertDialog.Builder(Activity)
.SetView(view)
.SetPositiveButton(GetString(Resource.String.lblCarProfileDialogOK), (sender, args) =>
{
// The datasouce source update works
datasource.UpdateCarProfile(id, txtName.Text, txtPlateNumber.Text, spnCategoryColor.SelectedItem.ToString(), spnCategoryNumber.SelectedItem.ToString());
// But this doesn't
mainListAdapter.NotifyDataSetChanged();
})
.SetNegativeButton(GetString(Resource.String.lblCarProfileDialogCancel), (sender, args) =>
{
Dialog.Dismiss();
})
.SetTitle(GetString(Resource.String.lblCarProfileDialogTitle));
return builder.Create();
}
}
위에 AlertDialog의 코드와 같이하고 나는를 호출 할 때 NotifyDataSetChanged
메서드는 아무 일도 발생하지 않습니다. NotifyDataSetChanged()
때문에
컴파일 된 적이 있습니까? 이 파일에는 몇 가지 Java synxtax 오류가 있습니다. – Snicolas
이것은 단괴이다. Java 솔루션을 사용해도 괜찮습니다. – Ron
MonoDroid에 대해서는 말할 수 없지만, 일반적인 자바에서는 이벤트 기반 메커니즘을 사용하여 프래그먼트가 활동과 통신 할 수 있도록해야합니다. 그런 다음 목록을 새로 고칩니다. http://stackoverflow.com/questions/10867425/communication-between-fragments-dialogs-in-android – Snicolas