完成 学拼音
parent
9096d93bad
commit
6fc7c018cb
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="C:\Users\wanghao\.android\avd\Nexus_10_API_33.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-10-28T05:42:02.521700100Z" />
|
||||
</component>
|
||||
</project>
|
@ -1,106 +0,0 @@
|
||||
package com.example.readtext.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.readtext.R;
|
||||
import com.example.readtext.been.ReadTextBeen;
|
||||
import com.example.readtext.databinding.ItemMainBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LearnPinyinAdapter extends RecyclerView.Adapter<LearnPinyinAdapter.MyViewHolder> {
|
||||
private Context context;
|
||||
private List<ReadTextBeen> list;
|
||||
private MyClickInterface clickInterface;
|
||||
private LayoutInflater layoutInflater;
|
||||
private List<Boolean> selectedList;
|
||||
private boolean aBoolean=false;
|
||||
public void setaBoolean(boolean aBoolean) {
|
||||
this.aBoolean = aBoolean;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public LearnPinyinAdapter(Context context, MyClickInterface clickInterface) {
|
||||
this.context = context;
|
||||
this.clickInterface = clickInterface;
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
public void setList(List<ReadTextBeen> list) {
|
||||
this.list = list;
|
||||
int size = list.size();
|
||||
setSelectedList(size);
|
||||
|
||||
}
|
||||
|
||||
public void setSelectedList(int size) {
|
||||
selectedList = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
selectedList.add(false);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ItemMainBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.item_main, parent, false);
|
||||
return new MyViewHolder(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
// Log.e("TAG", "onBindViewHolder:运行"+position );
|
||||
ReadTextBeen readTextBeen = list.get(position);
|
||||
ItemMainBinding binding = holder.binding;
|
||||
binding.setItem(readTextBeen);
|
||||
binding.setState(aBoolean);
|
||||
if (selectedList.get(position)) {
|
||||
// 设置选中时的颜色
|
||||
binding.itemView.setBackgroundResource(R.drawable.item_main_bg2);
|
||||
} else {
|
||||
// 设置未选中时的颜色
|
||||
binding.itemView.setBackgroundResource(R.drawable.item_bg);
|
||||
}
|
||||
|
||||
binding.itemHanzi.setOnClickListener(v -> {
|
||||
clickInterface.onClickCall(position);
|
||||
// 切换选中状态
|
||||
int size = selectedList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (selectedList.get(i)){
|
||||
selectedList.set(i,false);
|
||||
}
|
||||
}
|
||||
selectedList.set(position,true);
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
binding.itemDelete.setOnClickListener(v -> clickInterface.onClickUpdateCall(position));
|
||||
binding.itemPinyin.setOnClickListener(v -> clickInterface.onPinyinClick(position));
|
||||
holder.binding.executePendingBindings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list == null ? 0 : list.size();
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
private ItemMainBinding binding;
|
||||
|
||||
public MyViewHolder(ItemMainBinding binding) {
|
||||
super(binding.getRoot());
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">学习工具</string>
|
||||
<string name="app_name">学习工具(学拼音版)2.0</string>
|
||||
<string name="xiaoyu"><![CDATA[<]]></string>
|
||||
</resources>
|
Loading…
Reference in New Issue