Такая проблем! Я сделал SwipeRefresh и теперь когда прокручиваешь вверх включается свайп, а нужно крутить список доверху. Как исправить этот баг? Есть способ установить приоритет ListView перед Swipe?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/refresher">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<Button
android:text="Insert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonMainInsert" />
<ListView
android:choiceMode="multipleChoice"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listViewMain" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Код MainActivity
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
listview = FindViewById<ListView>(Resource.Id.listViewMain);
var txt1 = FindViewById<TextView>(Android.Resource.Id.Text1);
refresh = FindViewById<SwipeRefreshLayout>(Resource.Id.refresher);
refresh.Refresh += refresher_refresh;
listview.ItemClick += (s, e) =>
{
if (inActionMode)
{
adapter.ToggleSelection(e.Position);
_mode.Title = (adapter.SelectedCount.ToString() + " selected");
return;
}
Intent intent = new Intent(this, typeof(UpdateItemActivity));
intent.PutExtra("Id", e.Id);
StartActivity(intent);
};
listview.ItemLongClick += (s, e) =>
{
adapter.ToggleSelection(e.Position);
var hasCheckedItems = adapter.SelectedCount > 0;
if (hasCheckedItems && _mode == null)
_mode = StartActionMode(this);
else if (!hasCheckedItems && _mode != null)
_mode.Finish();
if (_mode != null)
_mode.Title = (adapter.SelectedCount.ToString() + " selected");
};
var btn = FindViewById<Button>(Resource.Id.buttonMainInsert);
btn.Click += delegate
{
Intent intent = new Intent(this, typeof(UpdateItemActivity));
StartActivity(intent);
};
}
private void refresher_refresh (object sender, EventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
worker.RunWorkerAsync();
}
private void worker_DoWork (object sender, DoWorkEventArgs e)
{
Random random = new Random();
int a = random.Next(0, 1000);
Item item1 = new Item { Title = "test" + a , Description = "Descc" + a };
db.InsertIntoTableItem(item1);
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
RunOnUiThread(() =>
{
refresh.Refreshing = false;
lstSource = db.SelctedTableItem();
adapter = new HomeScreenAdapter(this, lstSource);
listview.Adapter = adapter;
//RegisterForContextMenu(listview);
});
}
SwipeRefreshLayout
толькоListView
. – post_zeew 28 июл '17 в 10:15