- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
1.实体(表)CurrentyEnitiy.java
@Entity(tableName = "Corona")
public class CurrentyEntity {
@PrimaryKey(autoGenerate = true)
private int id;
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@NonNull
@ColumnInfo (name = "country")
private String country;
@NonNull
public String getCountry() {
return this.country;
}
@ColumnInfo (name = "infections_count")
private int infections_count;
public int getInfections_count() {
return this.infections_count;
}
public CurrentyEntity (@NonNull String country, int infections_count){
this.country = country;
this.infections_count = infections_count;
}
@Ignore
public CurrentyEntity (int id, String country , int infections_count){
this.id = id;
this.country = country;
this.infections_count = infections_count;
}
}
2.道PlayerDao.class
import java.util.List;
@Dao
public interface PlayerDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
void insert(CurrentyEntity player);
@Update
void update(CurrentyEntity...players);
// how to delete a colummn value for a row
@Delete
void delete(CurrentyEntity player);
// how to return a specific row ??
@Query("SELECT * FROM Corona ORDER BY infections_count ASC ")
LiveData<List<CurrentyEntity>> returnRowLowToHigh();
@Query("SELECT COUNT(*) FROM Corona")
Integer getRowCount();
}
3. session 室数据库RoomDB.class
@Database(entities = {CurrentyEntity.class}, version = 2, exportSchema = false)
public abstract class RoomDB extends RoomDatabase {
public abstract PlayerDao PlayerDao();
private static RoomDB INSTANCE;
public static RoomDB getINSTANCE(final Context context){
if (INSTANCE == null)
{
synchronized (RoomDB.class)
{
if (INSTANCE == null)
{
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), RoomDB.class,"pumpin_DataBase")
// Wipes and rebuilds instead of migrating
// if no Migration object.
// Migration is not part of this practical.
.fallbackToDestructiveMigration()
.addCallback(afterOpeningRoomDB)
.build();
}
}
}
return INSTANCE;
}
// // the only 2 callback methods
// //void onCreate(SupportSQLiteDatabase db)
// //Called when the database is created for the first time.
// //
// //void onOpen(SupportSQLiteDatabase db)
// //Called when the database has been opened.
private static RoomDatabase.Callback afterOpeningRoomDB = new RoomDatabase.Callback(){
@Override
public void onOpen(@NonNull SupportSQLiteDatabase db) {
super.onOpen(db);
new LaunchAsyncTask(INSTANCE).execute();
}
};
private static class LaunchAsyncTask extends AsyncTask<Void,Void,Void>{
private final PlayerDao DAO;
public LaunchAsyncTask(RoomDB db){
DAO = db.PlayerDao();
}
@Override
protected Void doInBackground(final Void... voids) {
DAO.insert(new CurrentyEntity("jordan",3434));
return null;
}
}
}
4.存储库AllRepository.class
public class AllRepository {
private PlayerDao playerDao;
private LiveData<List<CurrentyEntity>> rowList;
private static String rowCount;
AllRepository(Application application){
RoomDB roomdb = RoomDB.getINSTANCE(application);
playerDao = roomdb.PlayerDao();
rowList = playerDao.returnRowLowToHigh();
}
LiveData<List<CurrentyEntity>> returnRowList () {return rowList;}
public void RemoveRow(CurrentyEntity row){ new removeRow(playerDao).execute(row);}
public void AddRow(CurrentyEntity row) { new addRow(playerDao).execute(row);}
public void UpdateRow(CurrentyEntity row){ new updateRow(playerDao).execute(row);}
public String getRowCount(){ new getRowCount(playerDao).execute();
return rowCount; }
private static class removeRow extends AsyncTask<CurrentyEntity,Void,Void> {
private PlayerDao removePlayerDao;
public removeRow(PlayerDao currentDao){
removePlayerDao = currentDao;
}
@Override
protected Void doInBackground(CurrentyEntity... players) {
removePlayerDao.delete(players[0]);
return null;
}
}
private static class addRow extends AsyncTask<CurrentyEntity,Void,Void> {
private PlayerDao addPlayerDao;
public addRow(PlayerDao currentDao){
addPlayerDao = currentDao;
}
@Override
protected Void doInBackground(CurrentyEntity... players) {
addPlayerDao.insert(players[0]);
return null;
}
}
private static class updateRow extends AsyncTask<CurrentyEntity,Void,Void> {
private PlayerDao updatePlayerDao;
public updateRow(PlayerDao currentDao){
updatePlayerDao = currentDao;
}
@Override
protected Void doInBackground(CurrentyEntity... players) {
updatePlayerDao.update(players[0]);
return null;
}
}
private static class getRowCount extends AsyncTask<CurrentyEntity,Void,Void> {
private PlayerDao addPlayerDao;
public getRowCount(PlayerDao currentDao){
addPlayerDao = currentDao;
}
@Override
protected Void doInBackground(CurrentyEntity... players) {
rowCount = String.valueOf(addPlayerDao.getRowCount());
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
}
** 5。 ViewModel AllViewModel.class **
public class AllViewModel extends AndroidViewModel {
private AllRepository allRepository;
private LiveData<List<CurrentyEntity>> rowList;
public AllViewModel( Application application) {
super(application);
allRepository = new AllRepository(application);
rowList = allRepository.returnRowList();
}
LiveData<List<CurrentyEntity>> returnRowList(){ return rowList;}
public void removeRow(CurrentyEntity row){ allRepository.RemoveRow(row);}
public void addRow(CurrentyEntity row){ allRepository.AddRow(row);}
public void updateRow(CurrentyEntity row){ allRepository.UpdateRow(row);}
public String getRowCount(){ return allRepository.getRowCount();}
}
6. RecyclerView适配器MenWomenRecycler.class
public class MenWomenRecycler extends RecyclerView.Adapter<MenWomenRecycler.MenWomenViewHolder> {
private final LayoutInflater mInflater;
private List<CurrentyEntity> listOfCases;
MenWomenRecycler(Context context) {
mInflater = LayoutInflater.from(context);
}
public void setList(List<CurrentyEntity> incomingList ){
listOfCases = incomingList;
notifyDataSetChanged();
}
@NonNull
@Override
public MenWomenViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = mInflater.inflate(R.layout.view_holder_men_women, parent, false);
return new MenWomenViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull MenWomenViewHolder holder, int position) {
CurrentyEntity currentCase = listOfCases.get(position);
TextView first = holder.cardView.findViewById(R.id.men_women_count);
first.setText(currentCase.getCountry());
TextView secound = holder.cardView.findViewById(R.id.men_women_country);
secound.setText(Integer.toString(currentCase.getInfections_count()));
// Warning : maybe I shouldve used String.format instead
}
// if this is set to 0 it fucks up the whole thing. RecyclerView'ss contents won't be displayed
// getItemCount() is called many times, and when it is first called,
// mWords has not been updated (means initially, it's null, and we can't return null).
@Override
public int getItemCount() {
if(listOfCases != null){
Log.w("Row Count", String.valueOf(listOfCases.size()));
return listOfCases.size();
} else return 0;
}
class MenWomenViewHolder extends RecyclerView.ViewHolder {
/* private final TextView Country;
private final TextView count;
Country = itemView.findViewById(R.id.men_women_country);
count = itemView.findViewById(R.id.men_women_count);
*/
private CardView cardView;
public MenWomenViewHolder(@NonNull View itemView) {
super(itemView);
cardView = (CardView) itemView;
}
}
}
** 7。 HomeActivity.Class **
public class HomeActivity extends AppCompatActivity {
private Button signout;
private AllViewModel viewModel;
private RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
recyclerView = findViewById(R.id.men_women_recycler);
final MenWomenRecycler adapter = new MenWomenRecycler(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
Log.w("look for this in the log", "touchin when kb is null");
viewModel = ViewModelProviders.of(this).get(AllViewModel.class);
viewModel.returnRowList().observe(this,new Observer<List<CurrentyEntity>>() {
@Override
public void onChanged(@Nullable final List<CurrentyEntity> listOfCases) {
adapter.setList(listOfCases);
}
});
String rowCount = String.valueOf(viewModel.getRowCount());
viewModel.addRow(new CurrentyEntity("EASY", 23));
viewModel.addRow(new CurrentyEntity("letsee", 233));
** 8. HomeActivity的XML布局文件**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".HomeActivity">
<!-- tools:listitem="@layout/view_holder_men_women"
this makes it possible to have a preview of the RecyclerView-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/men_women_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:listitem="@layout/view_holder_men_women"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/SIGNOUT"
android:text="@string/signOut"
/>
</LinearLayout>
这是问题所在:
viewModel.addRow(new CurrentyEntity("EASY", 23));
viewModel.addRow(new CurrentyEntity("letsee", 233));
并坚持在RoomDB.class中插入一行的第一个声明
DAO.insert(new CurrentyEntity("jordan",3434));
到目前为止一切正常,他们的回收站只会显示一个View(viewHolder)
最佳答案
发生这种情况是由于以下原因。
首次启动该应用程序时,它将在数据库中输入3个条目。
RoomDb类(约旦1个)中的1个条目,家庭 Activity 类中的2个条目。
现在,如果您通过按设备后退按钮关闭应用程序并重新打开它,它将在数据库中另外创建两个条目(家庭 Activity 条目(easy&letsee)。
RoomDB类(乔丹之一)将没有条目,因为DB连接仍处于打开状态。所以
new LaunchAsyncTask(INSTANCE).execute();
将不会执行。
@NonNull
@PrimaryKey
@ColumnInfo(name = "country")
private String country;
关于java - Android Studio- Java RecyclerView显示的 View (所有者)多于 session 室数据库中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65730100/
是否为每个 Shiny session 分配了 session ID/ session key (如果部署在 Shiny 服务器上)?如果是,我如何访问该信息?我已阅读文档here然而上网查了一下,并
我正在使用 this koajs session 模块。 我检查了源代码,但我真的无法理解。 我想知道它保存 session 数据的位置,因为我没有看到创建的文件,并且当服务器重新启动时, sessi
实现高可扩展性的一种方法是使用网络负载平衡在多个服务器之间分配处理负载。 这种方法提出的一个挑战是服务器是否具有状态意识 - 将用户状态存储在“ session ”中。 此问题的一个解决方案是“粘性
在负载平衡服务器的上下文中, session 亲和性和粘性 session 之间有什么区别? 最佳答案 我见过这些术语可以互换使用,但有不同的实现方式: 在第一个响应中发送 cookie,然后在后续响
我希望其他人向我解释哪种方法更好:使用 session 或设计无 session 。我们正在开始开发一个新的 Web 应用程序,但尚未决定要遵循什么路径。 无 session 设计在我看来更可取: 优
现在用户在他的权限中有很多角色,我将允许他点击 href 并在新窗口中扮演另一个角色。每个角色都有自己的 session 。 既然浏览器打开窗口不能用新 session 打开,我必须在服务器端想办法。
我正在尝试为express.js Node 应用程序实现 session 存储我的问题是: 如何删除具有浏览器 session 生命周期的 cookie(根据连接文档标记有 expires = fal
在开始在 golang 中使用 session 之前,我需要回答一些问题 session 示例 import "github.com/gorilla/sessions" var store = ses
我读过 Namespaced Attributes . 我尝试使用此功能: #src/Controller/CartController.php public function addProduct(
我正在努力完成以下工作: 根据用户的类型更改用户的 session cookie 到期日期。 我有一个 CakePHP Web 应用程序,其中我使用 CakePHP session 创建了我的身份验证
这是我在这里的第一个问题,我希望我做对了。 我需要处理一个 Java EE 项目,所以在开始之前,我会尝试做一些简单的事情,看看我是否能做到。 我坚持使用有状态 session Bean。 这是问题:
ColdFusion session 与 J2EE session 相比有什么优势吗? ColdFusion session documentation提到了 J2EE session 的优点,但没有
在执行任何任务之前,我需要准确地在创建 session 时创建一个 session 范围变量(因为我的所有任务都需要一个初始 session 范围变量才能运行)。因为,创建 session 时,gra
我们当前的应用使用 HTTP session ,我们希望将其替换为 JWT。 该设置仅允许每个用户进行一次 session 。这意味着: 用户在设备 1 上登录 用户已在设备 1 上登录(已创建新 s
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
假设我在两个或更多设备上打开了两个或更多用户 session (同一用户没有管理员权限)。 在当前 session 中,如果我注销,是否意味着所有其他 session 也会关闭?如果没有,有没有办法通
我正在评估在 tomcat 中使用带有 session 复制的粘性 session 的情况。根据我的初步评估,我认为如果我们启用 session 复制,那么在一个 tomcat 节点中启动的 sess
我开始使用 golang 和 Angular2 构建一个常规的网络应用程序,最重要的是我试图在 auth0.com 的帮助下保护我的登录.我从 here 下载快速入门代码并尝试运行代码,它运行了一段时
我在 Spring Controller 中有一个方法,它接受两个相同类型的参数其中一个来自 session ,另一个来自表单提交(UI)。 问题是在 Controller 方法中我的非 sessio
在我登录之前,我可以点击我的安全约束目录之外的任何内容。如果我尝试转到安全约束目录内的某个位置,它会将我重定向到表单登录页面。如您所料。 登录后,我可以继续我的业务,并访问我的安全约束内外的资源。
我是一名优秀的程序员,十分优秀!