七禾

文章 评论 浏览 29

七禾 2025-02-08 02:24:43

与文本文件中给出的几行编码有点困难,但请尝试一下:

temp = []
with open('Pafos.txt', 'r') as f:
    parcelIds_list = f.readlines()
    for j in parcelIDS_list:
         temp.extend(j.split(", "))
    new_list = [i.strip()[1:-1] for i in temp]
    print(new_list)
    

让我知道这是否不起作用以及出了什么问题。我将同样修改答案。

It is a bit hard to code with the few lines you have given from the text file, but try this :

temp = []
with open('Pafos.txt', 'r') as f:
    parcelIds_list = f.readlines()
    for j in parcelIDS_list:
         temp.extend(j.split(", "))
    new_list = [i.strip()[1:-1] for i in temp]
    print(new_list)
    

Let me know if this doesn't work, and what went wrong. I will modify my answer likewise.

如何读取txt文件的内容逗号分开并将其添加到列表中?

七禾 2025-02-08 01:42:06

我认为发生此错误是因为护照使用req.Session.Regenerate()函数内部功能(

cookie-session github页面上还有一个问题,该页面与recenerate函数有关(问题链接)。

如果将会话保留在客户端上并不重要,则可以将其保留在服务器端,可以使用 Express-Session 为此,您将无法获得上述错误。

I think this error happens because the passport use req.session.regenerate() function internally (source code link), cookie-session has not regenerate method and therefor passport throws the error.

There is also an issue on the cookie-session GitHub page that is related to regenerate function (issue link).

If it is not important to keep the session on the client-side, you can keep it on the server-side, you can use express-session for this, then you will not get the above error.

TypeError:req.session.regeneres不是使用护照的功能

七禾 2025-02-07 21:31:27

为我工作。请检查附件的图像以查看输出

from dateutil.parser import *
import pandas as pd
import numpy as np

df = pd.DataFrame({'Customer': ['ABC','XYZ','PQR'],
                   'Call_Date': ['12/8/2021 2:31:07 PM','20/8/2021 5:27:02 AM','5/8/2021 7:29:40 PM'],
                   'Transaction_Date': ['16/8/2021 9:21:58 PM','','']})

df['DUR'] = df.apply(lambda x : parse(x.Call_Date,fuzzy=True) - parse(x.Transaction_Date,fuzzy=True) if \
                     len(x.Transaction_Date) != 0 else np.nan, axis=1)

另一种方法可以用作以下内容,包括一个函数diff()以实现异常处理,因此现在对于任何类型的null/string/datetime来说,这都不是问题。

请查看库文档: https://dateutil.readthedutil.readthedocs.io of .html

def diff(datetime_old, datetime_new):
    try: return abs(parse(str(datetime_new), fuzzy=True) - parse(str(datetime_old), fuzzy=True))
    except: return np.nan

df['DUR'] = df.apply(lambda x : diff(x.Call_Date, x.Transaction_Date) if pd.notnull(x.Transaction_Date) else np.nan, axis=1)

https://i.sstatic.net/IIkBx.jpg

following working for me. please check the attached image to see output

from dateutil.parser import *
import pandas as pd
import numpy as np

df = pd.DataFrame({'Customer': ['ABC','XYZ','PQR'],
                   'Call_Date': ['12/8/2021 2:31:07 PM','20/8/2021 5:27:02 AM','5/8/2021 7:29:40 PM'],
                   'Transaction_Date': ['16/8/2021 9:21:58 PM','','']})

df['DUR'] = df.apply(lambda x : parse(x.Call_Date,fuzzy=True) - parse(x.Transaction_Date,fuzzy=True) if \
                     len(x.Transaction_Date) != 0 else np.nan, axis=1)

Another approach can be used as following, include a function diff() to implement exception handling so now it would not be a problem for any type Null/String/datetime.

please check library docs: https://dateutil.readthedocs.io/en/stable/parser.html

def diff(datetime_old, datetime_new):
    try: return abs(parse(str(datetime_new), fuzzy=True) - parse(str(datetime_old), fuzzy=True))
    except: return np.nan

df['DUR'] = df.apply(lambda x : diff(x.Call_Date, x.Transaction_Date) if pd.notnull(x.Transaction_Date) else np.nan, axis=1)

在两行中找到差异,其中一个可以在python中为null

七禾 2025-02-07 19:46:18

尝试:

// Change your response type
public equipmentPreparationData$(deviceID: string): Observable<any> {
 return forkJoin({
    regions: this.regions$,
    devices: this.getDevices(deviceID)
});


private getDevices(id: string): Observable<IEquipmentRow[]> {
    const url = `${apiUrl}/${id}`;
    return this.http.get<IGetDevicesResponse>(url)
      .pipe(
        map(res => {
          return res.data;
        })
      );
}

private regions$ = this.getRegions();

这样,您可以将函数与参数一起使用,并通过getDevices方法

Try with:

// Change your response type
public equipmentPreparationData$(deviceID: string): Observable<any> {
 return forkJoin({
    regions: this.regions$,
    devices: this.getDevices(deviceID)
});


private getDevices(id: string): Observable<IEquipmentRow[]> {
    const url = `${apiUrl}/${id}`;
    return this.http.get<IGetDevicesResponse>(url)
      .pipe(
        map(res => {
          return res.data;
        })
      );
}

private regions$ = this.getRegions();

In this way, you can use your function with the parameter and pass through getDevices method

使用RXJS forkjoin时传递参数的最佳方法

七禾 2025-02-07 19:24:52

输出是神经网络的输出,它代表了预定义类的概率。似乎总类号为9,因为输出的大小是9。

因此,预测是最讨人喜欢的类的索引。

而且,由于输入变换和本身的随机性,网络的预测可能会发生变化。我建议这样修改您的代码:

DEFAULT_MODEL_PATH = 'models/artemis/best_model.pt'

model = torch_load_model(DEFAULT_MODEL_PATH, 'cpu')
model.eval()
# print(c)
 
image = Image.open("sample_images/neoclassicism_romantics_art_nouveau.jpg")

# this section to transform I don't know what it does 

trans = transforms.Compose([
#    transforms.RandomHorizontalFlip(),
    transforms.Resize(32),
#    transforms.CenterCrop(32),
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
input = trans(image)

input = input.view(1, 3, 32, 32)
with torch.no_grad():
    output = model(input)
    prediction = int(torch.max(output.data, 1)[1].numpy())
print(output)
print(prediction)
  • model.eval()在网络中更改一些操作(batchnorm,辍学等),以丢弃
  • 推理transforms.randomhorizo​​ntalflip()用于删除随机性
  • 丢弃transforms.centercrop(32),因为它似乎无能为力,因为图像已
  • 用torch.no_grad()告诉TORCH不要计算

梯度建议受到欢迎

output is the output of the neural network, which represents the probability of pre-defined classes. It seems that the total class number is 9 since the size of the output is 9.

Therefore, prediction is the index of the most likable class.

And also, the network's prediction could change due to the randomness of input transforms and itself. I recommend modifying your code like this:

DEFAULT_MODEL_PATH = 'models/artemis/best_model.pt'

model = torch_load_model(DEFAULT_MODEL_PATH, 'cpu')
model.eval()
# print(c)
 
image = Image.open("sample_images/neoclassicism_romantics_art_nouveau.jpg")

# this section to transform I don't know what it does 

trans = transforms.Compose([
#    transforms.RandomHorizontalFlip(),
    transforms.Resize(32),
#    transforms.CenterCrop(32),
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
input = trans(image)

input = input.view(1, 3, 32, 32)
with torch.no_grad():
    output = model(input)
    prediction = int(torch.max(output.data, 1)[1].numpy())
print(output)
print(prediction)
  • model.eval() changes some operations (batchnorm, dropout, etc) in the network for inference
  • Discard transforms.RandomHorizontalFlip() for removing randomness
  • Discard transforms.CenterCrop(32) since it seems to do nothing since the image has resized to size of 32
  • with torch.no_grad() tells torch not to compute gradient

Any advise is welcomed

我如何预测使用受过训练的图像到情感pytorch模型

七禾 2025-02-07 11:45:59

根据文档,中间件应该是可召唤的(__call__方法的功能或类) https://docs.djangoproject.com/en/4.0/topics/http/http/middleware/#writing-your-your-your-your-your-now-middleware

结构应该像:

class SimpleMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.

    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.

        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        return response

According to docs Middleware should be a callable (function or class with __call__ method) https://docs.djangoproject.com/en/4.0/topics/http/middleware/#writing-your-own-middleware

Structure should be like:

class SimpleMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.

    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.

        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        return response

Django中间件对象不可呼应

七禾 2025-02-07 11:22:56

A couple of issues

See Playground
首先,您的请求属性当前无法删除(?。)。
因此必须是;

请求?:userInterface [];

则需要进行null cocece:

everyuser?。requecests?。[index];

其次,如果可以进行无效的情况, 获取对象可能是“未定义的”。(2532)错误。

A couple of issues

See Playground
Firstly your requests property is not nullable (?.) currently.
So it needs to be;

requests?: userInterface[];

Secondly, if it's nullable you'll need to do a null coalesce:

eachUser?.requests?.[index];

Otherwise you'd get a Object is possibly 'undefined'.(2532) error.

声明对象的密钥类型在反应打字稿中

七禾 2025-02-07 11:07:57

首先,将下面的代码放在build.gradle(模块)侧面Android支架的

buildFeatures{
        viewBinding true
    }

步骤1中 - 在主活动中创建循环器视图xml布局xml布局

<?xml version="1.0" encoding="utf-8"?>
<!-- 1 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycle_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ></androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>

步骤2-创建自定义项目布局xml,然后右键单击布局new - &gt;布局资源文件

<?xml version="1.0" encoding="utf-8"?>
<!-- 2 -->
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_click"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="3dp"
    app:cardCornerRadius="10dp"
    app:cardUseCompatPadding="true"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ImageView
            android:id="@+id/tv_logo"
            android:src="@color/black"
            android:padding="5dp"
            android:layout_width="100dp"
            android:layout_height="100dp" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="5dp">
            <TextView
                android:id="@+id/tv_title"
                android:text="Amazon"
                android:textSize="25sp"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:progressTint="#EFD80E"
                android:rating="3"
                style="@style/Widget.AppCompat.RatingBar.Indicator" />
        </LinearLayout>
    </LinearLayout>
</androidx.cardview.widget.CardView>

中创建项目类

 package com.example.recyclerviewdemonewwithinterface.model;


    // 3
    public class Item {
        private int id;
        private String name;
        private float rating;
        private int image;
    
        public Item(int id, String name, float rating, int image) {
            this.id = id;
            this.name = name;
            this.rating = rating;
            this.image = image;
        }
    
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public float getRating() {
            return rating;
        }
        public void setRating(float rating) {
            this.rating = rating;
        }
        public int getImage() {
            return image;
        }
        public void setImage(int image) {
            this.image = image;
        }
    }

步骤3-在Java步骤4

package com.example.recyclerviewdemonewwithinterface.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.recyclerviewdemonewwithinterface.SetOnClickListener;
import com.example.recyclerviewdemonewwithinterface.databinding.CustomItemLayoutBinding;
import com.example.recyclerviewdemonewwithinterface.model.Item;
import java.util.List;

// 4
public class CustomItemAdapter extends RecyclerView.Adapter<CustomItemAdapter.MyViewHolder> {
    CustomItemLayoutBinding binding;
    private Context context;
    private List<Item> itemList;
    // i3 & create constructor also
    private SetOnClickListener setOnClickListener;

    public CustomItemAdapter(Context context, List<Item> itemList, SetOnClickListener setOnClickListener) {
        this.context = context;
        this.itemList = itemList;
        this.setOnClickListener = setOnClickListener;
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        binding = CustomItemLayoutBinding.inflate(LayoutInflater.from(context),parent,false);
        MyViewHolder holder = new MyViewHolder(binding);
        return holder;
    }
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Item item = itemList.get(position);
        holder.binding.tvLogo.setImageResource(item.getImage());
        holder.binding.tvTitle.setText(item.getName());
        holder.binding.ratingBar.setRating(item.getRating());

        // i4
        holder.binding.cardClick.setOnClickListener(view -> {
            setOnClickListener.onItemClick(item,position);
        });
        // click event from adapter
        /*holder.binding.cardClick.setOnClickListener(v -> {
            Toast.makeText(context, ""+item.getName(), Toast.LENGTH_SHORT).show();
        });*/
    }
    @Override
    public int getItemCount() {
        return itemList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        CustomItemLayoutBinding binding;
        public MyViewHolder(@NonNull CustomItemLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}

- 在Java步骤5中创建customItemadapter类 - 在Java中创建SetOnClickListener接口,在Java

package com.example.recyclerviewdemonewwithinterface;

import com.example.recyclerviewdemonewwithinterface.model.Item;

// 6
public interface SetOnClickListener {
    // i1
    void onItemClick(Item item,int position);
    void onLongItemClick(Item item, int position);
}

步骤6中 - 在Main Activity Java中应用以下代码。

package com.example.recyclerviewdemonewwithinterface;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.recyclerviewdemonewwithinterface.adapter.CustomItemAdapter;
import com.example.recyclerviewdemonewwithinterface.databinding.ActivityMainBinding;
import com.example.recyclerviewdemonewwithinterface.model.Item;

import java.util.ArrayList;
import java.util.List;

// i2 & implement methods
public class MainActivity extends AppCompatActivity implements SetOnClickListener {
    // 5
    ActivityMainBinding binding;
    List<Item> itemList;
    CustomItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        prepareData();

        // i5 set interface in argument (Last this)
        adapter = new CustomItemAdapter(MainActivity.this, itemList, this);

        LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
        // to show listview horizontaly
        // LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this,LinearLayoutManager.HORIZONTAL,false);
        // to show grid view
        // GridLayoutManager layoutManager = new GridLayoutManager(MainActivity.this,3);
        // to show Straggered
        // StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
        // layout manager in recycle view
        binding.recycleView.setLayoutManager(layoutManager);
        binding.recycleView.setAdapter(adapter);
    }

    private void prepareData() {
        itemList = new ArrayList<>();

        itemList.add(new Item(1, "Instagram", 3.5f, R.drawable.ic_launcher_background));
        itemList.add(new Item(2, "Pinterest", 2.5f, R.drawable.ic_launcher_background));
        itemList.add(new Item(3, "YouTube", 3.f, R.drawable.ic_launcher_background));
        itemList.add(new Item(4, "Twitter", 5.5f, R.drawable.ic_launcher_background));
        itemList.add(new Item(5, "Whatsapp", 4.5f, R.drawable.ic_launcher_background));
    }

    @Override
    public void onItemClick(Item item, int position) {
        // i6
        // Toast.makeText(this, ""+itemList.get(position).getName(), Toast.LENGTH_SHORT).show();
        //
        Toast.makeText(this, "" + item.getId()+"___"+position, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLongItemClick(Item item, int position) {

    }
}

First of all put below code in build.Gradle(Module) in side android brackets

buildFeatures{
        viewBinding true
    }

Step 1 - Create recycler view in main activity xml layout

<?xml version="1.0" encoding="utf-8"?>
<!-- 1 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycle_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ></androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>

Step 2 - Create custom item layout xml By Right click on layout new -> layout Resource file

<?xml version="1.0" encoding="utf-8"?>
<!-- 2 -->
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_click"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="3dp"
    app:cardCornerRadius="10dp"
    app:cardUseCompatPadding="true"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ImageView
            android:id="@+id/tv_logo"
            android:src="@color/black"
            android:padding="5dp"
            android:layout_width="100dp"
            android:layout_height="100dp" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="5dp">
            <TextView
                android:id="@+id/tv_title"
                android:text="Amazon"
                android:textSize="25sp"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:progressTint="#EFD80E"
                android:rating="3"
                style="@style/Widget.AppCompat.RatingBar.Indicator" />
        </LinearLayout>
    </LinearLayout>
</androidx.cardview.widget.CardView>

Step 3 - Create Item Class in java

 package com.example.recyclerviewdemonewwithinterface.model;


    // 3
    public class Item {
        private int id;
        private String name;
        private float rating;
        private int image;
    
        public Item(int id, String name, float rating, int image) {
            this.id = id;
            this.name = name;
            this.rating = rating;
            this.image = image;
        }
    
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public float getRating() {
            return rating;
        }
        public void setRating(float rating) {
            this.rating = rating;
        }
        public int getImage() {
            return image;
        }
        public void setImage(int image) {
            this.image = image;
        }
    }

Step 4 - Create CustomItemAdapter Class in java

package com.example.recyclerviewdemonewwithinterface.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.recyclerviewdemonewwithinterface.SetOnClickListener;
import com.example.recyclerviewdemonewwithinterface.databinding.CustomItemLayoutBinding;
import com.example.recyclerviewdemonewwithinterface.model.Item;
import java.util.List;

// 4
public class CustomItemAdapter extends RecyclerView.Adapter<CustomItemAdapter.MyViewHolder> {
    CustomItemLayoutBinding binding;
    private Context context;
    private List<Item> itemList;
    // i3 & create constructor also
    private SetOnClickListener setOnClickListener;

    public CustomItemAdapter(Context context, List<Item> itemList, SetOnClickListener setOnClickListener) {
        this.context = context;
        this.itemList = itemList;
        this.setOnClickListener = setOnClickListener;
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        binding = CustomItemLayoutBinding.inflate(LayoutInflater.from(context),parent,false);
        MyViewHolder holder = new MyViewHolder(binding);
        return holder;
    }
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Item item = itemList.get(position);
        holder.binding.tvLogo.setImageResource(item.getImage());
        holder.binding.tvTitle.setText(item.getName());
        holder.binding.ratingBar.setRating(item.getRating());

        // i4
        holder.binding.cardClick.setOnClickListener(view -> {
            setOnClickListener.onItemClick(item,position);
        });
        // click event from adapter
        /*holder.binding.cardClick.setOnClickListener(v -> {
            Toast.makeText(context, ""+item.getName(), Toast.LENGTH_SHORT).show();
        });*/
    }
    @Override
    public int getItemCount() {
        return itemList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        CustomItemLayoutBinding binding;
        public MyViewHolder(@NonNull CustomItemLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}

Step 5 - Create SetOnClickListener Interface in java

package com.example.recyclerviewdemonewwithinterface;

import com.example.recyclerviewdemonewwithinterface.model.Item;

// 6
public interface SetOnClickListener {
    // i1
    void onItemClick(Item item,int position);
    void onLongItemClick(Item item, int position);
}

Step 6 - Apply Below code in Main Activity Java

package com.example.recyclerviewdemonewwithinterface;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.recyclerviewdemonewwithinterface.adapter.CustomItemAdapter;
import com.example.recyclerviewdemonewwithinterface.databinding.ActivityMainBinding;
import com.example.recyclerviewdemonewwithinterface.model.Item;

import java.util.ArrayList;
import java.util.List;

// i2 & implement methods
public class MainActivity extends AppCompatActivity implements SetOnClickListener {
    // 5
    ActivityMainBinding binding;
    List<Item> itemList;
    CustomItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        prepareData();

        // i5 set interface in argument (Last this)
        adapter = new CustomItemAdapter(MainActivity.this, itemList, this);

        LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
        // to show listview horizontaly
        // LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this,LinearLayoutManager.HORIZONTAL,false);
        // to show grid view
        // GridLayoutManager layoutManager = new GridLayoutManager(MainActivity.this,3);
        // to show Straggered
        // StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
        // layout manager in recycle view
        binding.recycleView.setLayoutManager(layoutManager);
        binding.recycleView.setAdapter(adapter);
    }

    private void prepareData() {
        itemList = new ArrayList<>();

        itemList.add(new Item(1, "Instagram", 3.5f, R.drawable.ic_launcher_background));
        itemList.add(new Item(2, "Pinterest", 2.5f, R.drawable.ic_launcher_background));
        itemList.add(new Item(3, "YouTube", 3.f, R.drawable.ic_launcher_background));
        itemList.add(new Item(4, "Twitter", 5.5f, R.drawable.ic_launcher_background));
        itemList.add(new Item(5, "Whatsapp", 4.5f, R.drawable.ic_launcher_background));
    }

    @Override
    public void onItemClick(Item item, int position) {
        // i6
        // Toast.makeText(this, ""+itemList.get(position).getName(), Toast.LENGTH_SHORT).show();
        //
        Toast.makeText(this, "" + item.getId()+"___"+position, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLongItemClick(Item item, int position) {

    }
}

如何在带有接口和cardView的回收瓶适配器中使用viewBinding和Android Java中的cardView?

七禾 2025-02-07 04:50:05

那是正常的结构。对于ngclass,它是:

[ngClass]="{'classname' : condition}"

因此,在您的情况下,只需这样使用...

<ol class="breadcrumb">
  <li [ngClass]="{'active': step==='step1'}" (click)="step='step1'">Step1</li>
  <li [ngClass]="{'active': step==='step2'}" (click)="step='step2'">Step2</li>
  <li [ngClass]="{'active': step==='step3'}" (click)="step='step3'">Step3</li>
</ol>

That's the normal structure. For ngClass, it is:

[ngClass]="{'classname' : condition}"

So in your case, just use it like this...

<ol class="breadcrumb">
  <li [ngClass]="{'active': step==='step1'}" (click)="step='step1'">Step1</li>
  <li [ngClass]="{'active': step==='step2'}" (click)="step='step2'">Step2</li>
  <li [ngClass]="{'active': step==='step3'}" (click)="step='step3'">Step3</li>
</ol>

Angular: *ngclass的有条件类

七禾 2025-02-07 01:54:00

这是一个新的警告

 * "git pull" issues a warning message until the pull.rebase
   configuration variable is explicitly given, which some existing
   users may find annoying---those who prefer not to rebase need to
   set the variable to false to squelch the warning.

”对于git pull,如果您不在命令行上指定行为(使用- ff- no -ff-ff-仅限- rebase)。在所有情况下,git都会尝试快速(什么是Git快进?)如果可能的话,合并。设置控制分支中发生变化的情况,但不存在时会发生什么。

  git config pull.rebase false  # merge (the default strategy)

这是现有的默认行为;将其设置为没有警告,也没有行为改变; git将将远程分支合并到您的本地分支中。

  git config pull.rebase true   # rebase

在这里,git将尝试在远程分支的顶部重新考虑您的更改。请参阅我何时应该使用git pull-rebase-rebase?有关更多详细信息?关于为什么您可能想要那个。

  git config pull.ff only       # fast-forward only

如果不可能快速合并,则git将拒绝继续进行。如 git pull-rebase and git-rebase和git pull之间-ff-仅报价:

拒绝以非零状态合并和退出,除非当前头已经是最新的,否则合并可以作为快速前向的

解决

This is a new warning added in Git 2.27:

 * "git pull" issues a warning message until the pull.rebase
   configuration variable is explicitly given, which some existing
   users may find annoying---those who prefer not to rebase need to
   set the variable to false to squelch the warning.

To remove the warning, set one of the suggested values to your preferred default behaviour for git pull if you don't specify behaviour on the command line (using --ff, --no-ff, --ff-only, --rebase). In all cases, git will attempt a fast-forward (What is git fast-forwarding?) merge if possible. The settings control what happens when there are changes in your branch but not present in the remote branch.

  git config pull.rebase false  # merge (the default strategy)

This is the existing default behaviour; set this for no warning, and no change in behaviour; git will merge the remote branch into your local one.

  git config pull.rebase true   # rebase

Here, git will attempt to rebase your changes on top of the remote branch. See When should I use git pull --rebase? for more detail on why you might want that.

  git config pull.ff only       # fast-forward only

If a fast-forward merge is not possible, git will refuse to proceed. As Difference between git pull --rebase and git pull --ff-only quotes:

Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward

我该如何处理此GIT警告? “拉动而没有指定如何调和分支的分支。”

七禾 2025-02-07 01:27:03

您可以将“ getureTector”窗口小部件与“ OnlongPress”属性一起使用。

更多信息: https://api.flutter.flutter.flutter.dev/flutter.dev/flutter.dev/flutter/gorgutter/gendetgets/genderueldetector /onlongpress.html

You can use 'GestureDetector' widget with 'onLongPress' property.

More information: https://api.flutter.dev/flutter/widgets/GestureDetector/onLongPress.html

在颤音中实施长按栏上的长按栏

七禾 2025-02-06 21:16:47

您可以使用Flex和Grid实现它。你是这样的吗?

.GameSelectList {
    list-style-type: none;
    display: flex;
    justify-content: space-evenly;
}

li.GameSelectListLin {
  display: grid;
  justify-content: center;
  text-align: center;
  }
<ul class="GameSelectList">
                <li class="GameSelectListLink">
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/MinecraftClassic.html"><img src="/Games/UnblockedGameImages/MinecraftClassic.webp" alt="Minecraft" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Minecraft Classic</figcaption>
                </li>
                
                <li class="GameSelectListLink">
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/1v1lol.html"><img src="/Games/UnblockedGameImages/1v1.lol.jpg" alt="1v1.lol" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>1v1.lol</figcaption>
                </li>
                
                <li class="GameSelectListLink">
                 
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/FortBuilding.html"><img src="/Games/UnblockedGameImages/FortBuilding.jfif" alt="Fort Building" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Fort Building</figcaption>
                </li>
                
                <li class="GameSelectListLink">               
               <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/GeoDash.html"><img src="/Games/UnblockedGameImages/GeometryDash.jfif" alt="Geometry Dash" width="100" height="100" class="GameSelectListLinkImg"></a>
               <figcaption>Geometry Dash</figcaption>
               </li>
                
                <li class="GameSelectListLink">               
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/motothree.html"><img src="/Games/UnblockedGameImages/Motox3m.webp" alt="Moto X3m" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Moto X3M</figcaption>
                </li>
                
                <li class="GameSelectListLink">                
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/tinyfishing.html"><img src="/Games/UnblockedGameImages/Tiny Fishing.webp" alt="Tiny Fishing" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Tiny Fishing</figcaption>
                </li>
                
</ul>

you can attain it using flex and grid. Do you mean like this?

.GameSelectList {
    list-style-type: none;
    display: flex;
    justify-content: space-evenly;
}

li.GameSelectListLin {
  display: grid;
  justify-content: center;
  text-align: center;
  }
<ul class="GameSelectList">
                <li class="GameSelectListLink">
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/MinecraftClassic.html"><img src="/Games/UnblockedGameImages/MinecraftClassic.webp" alt="Minecraft" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Minecraft Classic</figcaption>
                </li>
                
                <li class="GameSelectListLink">
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/1v1lol.html"><img src="/Games/UnblockedGameImages/1v1.lol.jpg" alt="1v1.lol" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>1v1.lol</figcaption>
                </li>
                
                <li class="GameSelectListLink">
                 
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/FortBuilding.html"><img src="/Games/UnblockedGameImages/FortBuilding.jfif" alt="Fort Building" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Fort Building</figcaption>
                </li>
                
                <li class="GameSelectListLink">               
               <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/GeoDash.html"><img src="/Games/UnblockedGameImages/GeometryDash.jfif" alt="Geometry Dash" width="100" height="100" class="GameSelectListLinkImg"></a>
               <figcaption>Geometry Dash</figcaption>
               </li>
                
                <li class="GameSelectListLink">               
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/motothree.html"><img src="/Games/UnblockedGameImages/Motox3m.webp" alt="Moto X3m" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Moto X3M</figcaption>
                </li>
                
                <li class="GameSelectListLink">                
                <a class="GameSelectListLinkA" href="/Games/UnblockedGameFiles/tinyfishing.html"><img src="/Games/UnblockedGameImages/Tiny Fishing.webp" alt="Tiny Fishing" width="100" height="100" class="GameSelectListLinkImg"></a>
                <figcaption>Tiny Fishing</figcaption>
                </li>
                
</ul>

图形将图像的右边而不是下面

七禾 2025-02-06 14:45:53

Webtable_page = WebTablePage

更改为

Webtable_page = WebTablePage()

Change the

Webtable_page = WebTablePage

to

Webtable_page = WebTablePage()

attributeError:键入对象&#x27; webtablepage&#x27;没有属性&#x27; load&#x27;在硒中使用pytest

七禾 2025-02-06 13:08:01

一些程序员的家伙是对的。只是MSVC ++不支持VLA。如果我有 -werror = vla ,我会因G ++和clang。
似乎没有办法使compiltime-evaluate and any any我能够满足某些程序员的强迫性欲望,而不会放弃nullptr:

template<typename Base, typename Class>
constexpr std::size_t offsetOf( Base Class::*r )
{
    union U
    {
        U() {}
        Class obj;
    } u;
    return (size_t)&(u.obj.*r) - (size_t)&u.obj;
}

Some programmer dude was right. It's just that MSVC++ doesn't support VLAs. If I have -Werror=vla I get an error with g++ and clang.
As it seems there's no way to have offsetOf compiletime-evaluateable anyay I can fulfill Some programmer dudes's compulsive desires with not dereferencing a nullptr:

template<typename Base, typename Class>
constexpr std::size_t offsetOf( Base Class::*r )
{
    union U
    {
        U() {}
        Class obj;
    } u;
    return (size_t)&(u.obj.*r) - (size_t)&u.obj;
}

nullpointer可以被“删除”。评估为constexpr?

七禾 2025-02-06 08:02:08

最好不要为此使用定位,如果您稍微更改模板,则可以这样实现:

html:

<div *ngIf="fullArticle" class="fullArticle">
   <header class="img_header">
      <img src="{{fullArticle?.imageUrl}}">
   </header>

   <main class="article_details_content">
      <div>{{fullArticle?.title}}</div>
      <div>{{fullArticle?.summary}}</div>
   </main>

  <footer class="footer" (click)="backToHomePage()">
     <mat-icon>west</mat-icon>
     Back to homepage
  </footer>
</div>

scss:

.fullArticle {
   display: flex;
   flex-direction: column;
   min-height: 100vh;
}
.img_header{   
   width: 100%;
   height: 217px; 
}

.article_details_content{
   flex-grow: 1;
}

It is better not to use positioning for this, if you change the template a little, you can implement it like this:

html:

<div *ngIf="fullArticle" class="fullArticle">
   <header class="img_header">
      <img src="{{fullArticle?.imageUrl}}">
   </header>

   <main class="article_details_content">
      <div>{{fullArticle?.title}}</div>
      <div>{{fullArticle?.summary}}</div>
   </main>

  <footer class="footer" (click)="backToHomePage()">
     <mat-icon>west</mat-icon>
     Back to homepage
  </footer>
</div>

scss:

.fullArticle {
   display: flex;
   flex-direction: column;
   min-height: 100vh;
}
.img_header{   
   width: 100%;
   height: 217px; 
}

.article_details_content{
   flex-grow: 1;
}

如何使用位置将中心块?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文