本篇文章给大家谈谈如何从ChangeNotifier推送路由?,同时本文还将给你拓展AndroidRecyclerView批量更新notifyItemRangeChanged、android–setR
本篇文章给大家谈谈如何从ChangeNotifier推送路由?,同时本文还将给你拓展Android RecyclerView批量更新notifyItemRangeChanged、android – setRangeNotifier(RangeNotifier)已被弃用?、android – 找不到方法createNotificationChannel(NotificationChannel)、axios发布请求后的vue-router推送路由等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- 如何从ChangeNotifier推送路由?
- Android RecyclerView批量更新notifyItemRangeChanged
- android – setRangeNotifier(RangeNotifier)已被弃用?
- android – 找不到方法createNotificationChannel(NotificationChannel)
- axios发布请求后的vue-router推送路由
如何从ChangeNotifier推送路由?
对我来说,这似乎对所有人都显而易见。您只需要将上下文传递到ChangeNotifier中即可,然后Navigator.pushNamed(context,routeName);
我正在寻找一种方法,可以从适当的小部件树中实现这一目标。我不是只从模型中进行操作-我仍然不确定这是最佳做法-但它有效。
,1. main.dart
MaterialApp(
navigatorKey: NavigationService().navigatorKey,)
2创建新课程
class NavigationService {
final GlobalKey<NavigatorState> navigatorKey =
new GlobalKey<NavigatorState>();
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
Future<dynamic> navigateTo(String routeName) {
return navigatorKey.currentState.pushNamed(routeName);
}}
-
在Model类中可在任何函数中使用
NavigationService>().navigateTo(homePageRoute) // your router name
Android RecyclerView批量更新notifyItemRangeChanged
附录1的文章,介绍RecyclerView的定点更新,现在介绍RecyclerView的批量更新,RecyclerView的批量更新通过notifyItemRangeChanged实现,notifyItemRangeChanged官方文档:
/**
* Notify any registered observers that the <code>itemCount</code> items starting at
* position <code>positionStart</code> have changed.
* Equivalent to calling <code>notifyItemRangeChanged(position, itemCount, null);</code>.
*
* <p>This is an item change event, not a structural change event. It indicates that
* any reflection of the data in the given position range is out of date and should
* be updated. The items in the given range retain the same identity.</p>
*
* @param positionStart Position of the first item that has changed
* @param itemCount Number of items that have changed
*
* @see #notifyItemChanged(int)
*/
public final void notifyItemRangeChanged(int positionStart, int itemCount) {
mObservable.notifyItemRangeChanged(positionStart, itemCount);
}
示例代码:
package zhangphil.demo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Random;
public class MainActivity extends Activity {
private ArrayList data = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i = 0; i < 5; i++) {
data.add(System.currentTimeMillis());
}
RecyclerView mRecyclerView = findViewById(R.id.recycler_view);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setOrientation(LinearLayout.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
final RecyclerView.Adapter mAdapter = new MyAdapter();
mRecyclerView.setAdapter(mAdapter);
final Random random = new Random();
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = random.nextInt(data.size());
for (int i = 0; i < count; i++) {
data.set(i, System.currentTimeMillis());
}
mAdapter.notifyItemRangeChanged(0, count);
}
});
}
private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
public MyAdapter() {
super();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(getApplicationContext()).inflate(android.R.layout.simple_list_item_2, null);
ViewHolder holder = new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
viewHolder.text1.setText(i + "");
viewHolder.text2.setText(data.get(i) + "");
}
@Override
public int getItemCount() {
return data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView text1;
public TextView text2;
public ViewHolder(View itemView) {
super(itemView);
text1 = itemView.findViewById(android.R.id.text1);
text1.setTextColor(Color.RED);
text2 = itemView.findViewById(android.R.id.text2);
text2.setTextColor(Color.BLUE);
}
}
}
}
附录:
1,《Android RecyclerView更新子项目notifyItemChanged》链接:http://blog.csdn.net/zhangphil/article/details/78565738
android – setRangeNotifier(RangeNotifier)已被弃用?
我正在使用alt.beacon库,现在我收到此警告:
warning: [deprecation] setRangeNotifier(RangeNotifier) in BeaconManager has been deprecated.
但更换的是什么?我需要对区域中的信标进行测距,并且回调RangeNotifier对于实现此功能至关重要.
public interface RangeNotifier {
void didRangeBeaconsInRegion(Collection<Beacon> var1, Region var2);
}
任何人都有一个新库如何工作的样本?
谢谢!
解决方法:
从版本2.9开始,您可能有多个RangeNotifier.所以不要打电话:
beaconManager.setRangeNotifier(rangeNotifier);
只需致电:
beaconManager.addRangeNotifier(rangeNotifier);
android – 找不到方法createNotificationChannel(NotificationChannel)
这是我创建NotificationChannel的代码:
notificationmanagerCompat notificationmanager = notificationmanagerCompat.from(this); // .. building mChannel,the NotificationChannel instance notificationmanager.createNotificationChannel(mChannel);
Android Studio告诉了这一点
Error:(67,32) error: cannot find symbol method createNotificationChannel(NotificationChannel)
我依赖于support-compat:27.0.0设置到我的core / build.gradle文件中:
compile 'com.android.support:support-compat:27.0.0'
解决方法
axios发布请求后的vue-router推送路由
好,终于我明白了。 this.$router.push()
返回的诺言我没有很好地处理。最终的解决方案如下:
axios.post('/user',{ email: this.email })
.then((response) => {
if (!response.data) {
void this.$router.push({ path: '/register',params: { user: defaultUser } });
} else {
void this.$router.push({ path: '/login',params: { user: response.data } });
}
})
.catch((error) => {
console.log(error);
});
由于拥有void
会触发eslint no-void
语法错误,并且我不在乎此promise的返回值,因此我通过添加/* eslint-disable no-void */
来抑制警告。
今天关于如何从ChangeNotifier推送路由?的讲解已经结束,谢谢您的阅读,如果想了解更多关于Android RecyclerView批量更新notifyItemRangeChanged、android – setRangeNotifier(RangeNotifier)已被弃用?、android – 找不到方法createNotificationChannel(NotificationChannel)、axios发布请求后的vue-router推送路由的相关知识,请在本站搜索。
本文标签: