小编Про*_*тлг的帖子

无法实时更新recycleView whith领域

对不起我的英语不好.我有列表对象,它列表包含switch btn.当用户更改某些交换机时,它会在db中更新.我但是当我尝试改变开关时,我有错误:

java.lang.IllegalStateException: Cannot modify managed objects outside of a write transaction.
Run Code Online (Sandbox Code Playgroud)

我无法理解如何创建适配器,谁可以更新实时数据

我的适配器:

   public class DocumentTypeAdapterDB extends RealmRecyclerViewAdapter<DocType, DocumentTypeAdapterDB.ViewHolder> {

    RealmList<DocType> docTypes;

    public DocumentTypeAdapterDB(@Nullable RealmList<DocType> docTypes, Context context) {
        super(docTypes, true);
        this.docTypes = docTypes;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_doc_type, null);
        RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutView.setLayoutParams(lp);
        ViewHolder rcv = new ViewHolder(layoutView);
        return rcv;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        final DocType docType = …
Run Code Online (Sandbox Code Playgroud)

android realm android-recyclerview

4
推荐指数
1
解决办法
3503
查看次数

AuthTokenSerializer。无效数据。期待一本字典,但得到了请求。姜戈

对不起我的英语不好。我正在学习 django rest,我想创建令牌授权。我是通过教程完成的,但是在将数据发送到服务器时出现错误

{
    "non_field_errors": [
        "Invalid data. Expected a dictionary, but got Request."
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的设置文件:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',

    'users',
]

..

..
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
    'PAGE_SIZE': 10,
     'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    )
}
Run Code Online (Sandbox Code Playgroud)

我的网址

urlpatterns = [
    url(r'^authtoken', views.ObtainAuthToken.as_view()),
]
Run Code Online (Sandbox Code Playgroud)

我的看法

class ObtainAuthToken(APIView):
    permission_classes = (permissions.AllowAny,)
    serializer_class = AuthTokenSerializer

    def post(self, request):
        serializer = self.serializer_class(data=request)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        token, created = Token.objects.get_or_create(user=user)
        return Response({'token': token.key}, status.HTTP_201_CREATED) …
Run Code Online (Sandbox Code Playgroud)

python django

1
推荐指数
1
解决办法
1782
查看次数

标签 统计

android ×1

android-recyclerview ×1

django ×1

python ×1

realm ×1