listview popup in Xamarin.android

时间:2015-07-28 16:04:19

标签: android xamarin xamarin.android

I have thoroughly searched already and then decided to ask here. I am trying to find an example of implementing a button when a user clicks, listview appears and when user clicks the button again, the listview disappears in xamarin.android

1 个答案:

答案 0 :(得分:1)

  1. 保留一个变量来控制ListView是否可见。
  2. 让您的活动实施Android.Views.View.IOnClickListener
  3. 点击按钮可更改ListView的可见性

    private bool _isShowing = false;
    
    //Don't forget to initialize those in your OnCreate 
    private ListView _listView;
    private Button _button;
    
    public void OnClick (View v)
    {
        _isShowing = !_isShowing;
        _listView.Visibility = _isShowing ? ViewStates.Visible : ViewStates.Gone;
    }
    
    //Inside your OnCreate, after initializing you button and your ListView
    _button.SetOnClickListener(this);
    
  4. 要使用流畅的动画,只需将其添加到.axml:

    android:animateLayoutChanges="true"
    

    我强烈建议使用MVVM方法,但由于你没有提到任何框架,这样就可以了。