Android 按钮单击Dialogox中的侦听器问题
我正在尝试从父对话框打开子对话框,它工作正常。里面有几个按钮。我面临的问题是单击侦听器在子对话框中没有响应,而且子对话框也没有关闭Android 按钮单击Dialogox中的侦听器问题,android,android-alertdialog,Android,Android Alertdialog,我正在尝试从父对话框打开子对话框,它工作正常。里面有几个按钮。我面临的问题是单击侦听器在子对话框中没有响应,而且子对话框也没有关闭 public class NoteListAdapter extends RecyclerView.Adapter<NoteListAdapter.NoteListHolder>{ private Context context; private LayoutInflater inflater; private ItemModel current;
public class NoteListAdapter extends RecyclerView.Adapter<NoteListAdapter.NoteListHolder>{
private Context context;
private LayoutInflater inflater;
private ItemModel current;
public List<ItemModel> data;
SubListAdapter adapter;
NoteListHolder holder;
String get_text;
EditText et_get_text;
AlertDialog alert_dialog, tag_alert_dialog;
String id;
LinearLayout tag_important, tag_study, tag_progress, tag_normal, tag_watchlist, tag_shopping, tag_food,tag_enterain,
tag_transport, tag_services, tag_health;
TextView set_date;
String tag_text, tag_color;
private List<TagsModel> tagList;
String note_id;
RecyclerView sub_recycler;
/* constructor */
public NoteListAdapter(Context context, List<ItemModel> data) {
inflater = LayoutInflater.from(context);
this.context = context;
this.data = data;
}
/* notify on item delete */
public void removeItem(int position) {
data.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}
/* delete all items */
public void removeAll() {
data.clear();
notifyDataSetChanged();
}
@Override
public NoteListAdapter.NoteListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View rootView = inflater.inflate(R.layout.note_recycler, parent, false);
holder = new NoteListHolder(rootView);
return holder;
}
@Override
public void onBindViewHolder(NoteListAdapter.NoteListHolder holder, int position) {
current = data.get(position);
// tag_current = tag_data.get(position);
String note_id = data.get(position).getId();
Log.d("note_idm","note id "+note_id);
ListNoteDataBase dataBase = new ListNoteDataBase(context);
dataBase.open();
dataBase.inserttags("abc ", note_id, "ef1232");
tagList = dataBase.getTagList(note_id);
String text = tagList.get(position).getTag();
String col = tagList.get(position).getTag_color();
final String input_text = current.getText();
holder.note_text.setText(input_text);
holder.tag_view.setText(text);
dataBase.close();
// holder.tagCircle.setColor(Color.parseColor("#" + col));
//holder.tagCircle.setColor(tag_color);*/
}
@Override
public int getItemCount() {
return data.size();
}
/* edit item from recycler view */
public void restoreItem(ItemModel item, int position) {
data.add(position, item);
notifyItemInserted(position);
}
/* declare and initialize NoteListHolder class*/
class NoteListHolder extends RecyclerView.ViewHolder{
private TextView note_text, tag_view;
public RelativeLayout viewBackground, viewForeground;
String note_txt_str;
LinearLayout add_tag;
Button tag_set;
public GradientDrawable tagCircle;
public NoteListHolder(View itemView) {
super(itemView);
note_text = itemView.findViewById(R.id.note_text);
viewBackground = itemView.findViewById(R.id.view_background);
viewForeground = itemView.findViewById(R.id.view_foreground);
tag_view = itemView.findViewById(R.id.tag_view);
tagCircle = (GradientDrawable) tag_view.getBackground();
viewForeground.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
note_id = data.get(pos).getId();
Log.d("note_id", "note id " + note_id);
Bundle b = new Bundle();
b.putString("note_id", note_id);
edit_dialog();
}
});
}
private void edit_dialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(R.layout.notedialog);
builder.setTitle("Edit Note");
// alert_dialog = builder.create();
alert_dialog = builder.show();
alert_dialog.show();
et_get_text = alert_dialog.findViewById(R.id.txtNote);
sub_recycler = alert_dialog.findViewById(R.id.recycler_dialog);
add_tag = alert_dialog.findViewById(R.id.add_tag);
add_tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(R.layout.tag_dialog);
builder.setTitle("Select Tag");
//tag_alert_dialog = builder.create();
tag_alert_dialog = builder.show();
tag_alert_dialog.getWindow().setGravity(Gravity.BOTTOM);
tag_alert_dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
tag_alert_dialog.show();
tag_important = tag_alert_dialog.findViewById(R.id.tag_imp);
tag_food = tag_alert_dialog.findViewById(R.id.tag_food);
tag_enterain = tag_alert_dialog.findViewById(R.id.tag_enterainment);
tag_normal = tag_alert_dialog.findViewById(R.id.tag_normal);
tag_health = tag_alert_dialog.findViewById(R.id.tag_health);
tag_transport = tag_alert_dialog.findViewById(R.id.tag_transport);
tag_study = tag_alert_dialog.findViewById(R.id.tag_study);
tag_services = tag_alert_dialog.findViewById(R.id.tag_services);
tag_shopping = tag_alert_dialog.findViewById(R.id.tag_shop);
tag_progress = tag_alert_dialog.findViewById(R.id.tag_progress);
tag_watchlist = tag_alert_dialog.findViewById(R.id.tag_watchlist);
tag_set = tag_alert_dialog.findViewById(R.id.set_tag);
tag_important.setOnClickListener(this);
tag_food.setOnClickListener(this);
tag_enterain.setOnClickListener(this);
tag_normal.setOnClickListener(this);
tag_health.setOnClickListener(this);
tag_transport.setOnClickListener(this);
tag_study.setOnClickListener(this);
tag_services.setOnClickListener(this);
tag_shopping.setOnClickListener(this);
tag_progress.setOnClickListener(this);
tag_watchlist.setOnClickListener(this);
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
tagList = appDatabase.getTagList(note_id);
String tag_id = tagList.get(getAdapterPosition()).getTagId();
int id = v.getId();
switch (id) {
case R.id.tag_imp:
tag_text = "Important";
tag_color = "C61F2B";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_progress:
tag_text = "Progress";
tag_color = "A50CE2";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_study:
tag_text = "Study";
tag_color = "FCA81D";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_watchlist:
tag_text = "Watchlist";
tag_color = "F4C664";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_normal:
tag_text = "Normal";
tag_color = "10CAC5";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_shop:
tag_text = "Shopping";
tag_color = "15B412";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_food:
tag_text = "Food & Drinks";
tag_color = "F15696";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_enterainment:
tag_text = "Entertainment";
tag_color = "A3128E";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_transport:
tag_text = "Transportation";
tag_color = "3324BD";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_services:
tag_text = "Services";
tag_color = "#F3C861";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_health:
tag_text = "Health";
tag_color = "EC4A3A";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
default:
tag_text = "";
tag_color = "ffffff";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
}
tag_set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// if (tag_alert_dialog.isShowing()) {
tag_alert_dialog.hide();
//}
}
});
}
});
final EditText et_sub_txt = alert_dialog.findViewById(R.id.et_subNote);
ImageButton sub_action = alert_dialog.findViewById(R.id.action_done);
sub_action.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String sub_text_str = et_sub_txt.getText().toString();
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
appDatabase.insertsubnotes(sub_text_str, note_id);
appDatabase.close();
subNote_adapter();
et_sub_txt.getText().clear();
et_sub_txt.clearFocus();
}
});
subNote_adapter();
set_date = alert_dialog.findViewById(R.id.creation_date);
String get_date = data.get(getAdapterPosition()).getDate();
set_date.setText(get_date);
String show_dia_text = data.get(getAdapterPosition()).getText();
id = data.get(getAdapterPosition()).getId();
//set_date.setText((CharSequence) update_date);
/*set cursor position */
note_txt_str = note_text.getText().toString();
et_get_text.setText(note_txt_str);
int position = show_dia_text.length();
et_get_text.setSelection(position);
Button button_edit_done = alert_dialog.findViewById(R.id.edit_note);
button_edit_done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
get_text = et_get_text.getText().toString().trim();
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
appDatabase.updateNotes(get_text, id);
appDatabase.close();
note_text.setText(get_text);
if (alert_dialog.isShowing()) {
alert_dialog.dismiss();
}
}
});
setOnDoneButton();
}
private void setOnDoneButton() {
et_get_text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
get_text = et_get_text.getText().toString().trim();
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
appDatabase.updateNotes(get_text, id);
appDatabase.close();
note_text.setText(get_text);
if (alert_dialog.isShowing()) {
alert_dialog.dismiss();
}
}
return false;
}
});
}
private void subNote_adapter() {
// recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL,false));
// recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
sub_recycler.setLayoutManager(new GridLayoutManager(context, 1));
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
adapter = new SubListAdapter(context, appDatabase.getSubList(note_id));
sub_recycler.setAdapter(adapter);
adapter.notifyDataSetChanged();
appDatabase.close();
}
}
公共类NoteListAdapter扩展了RecyclerView.Adapter{
私人语境;
私人充气机;
私有项目模型电流;
公开名单数据;
次级适配器;
票据持有人;
字符串获取文本;
编辑文本和获取文本;
警报对话框警报对话框,标记警报对话框;
字符串id;
线性布局tag_重要、tag_研究、tag_进度、tag_正常、tag_观察列表、tag_购物、tag_食品、tag_进站、,
tag_运输、tag_服务、tag_健康;
文本视图设置日期;
字符串标记\文本,标记\颜色;
私有列表标记列表;
字符串注释\u id;
RecyclerView sub_回收商;
/*建造师*/
公共NoteListAdapter(上下文、列表数据){
充气器=充气器。从(上下文);
this.context=上下文;
这个数据=数据;
}
/*删除项目时通知*/
公共无效删除项(内部位置){
数据删除(位置);
已移除(位置)的项目;
notifyDataSetChanged();
}
/*删除所有项目*/
公共无效删除所有(){
data.clear();
notifyDataSetChanged();
}
@凌驾
public NoteListAdapter.NoteListHolder onCreateViewHolder(视图组父级,int-viewType){
视图根视图=充气机。充气(R.layout.note\u recycler,parent,false);
holder=新的NoteListHolder(rootView);
报税表持有人;
}
@凌驾
BindViewHolder上的public void(NoteListAdapter.NoteListHolder,int位置){
当前=数据。获取(位置);
//tag\u current=tag\u data.get(位置);
String note_id=data.get(position.getId();
Log.d(“注释id”、“注释id”+注释id);
ListNoteDataBase=新的ListNoteDataBase(上下文);
open();
数据库。插入标签(“abc”,注释_id,“ef1232”);
tagList=dataBase.getTagList(注意id);
String text=tagList.get(position.getTag();
String col=tagList.get(position.getTag_color();
最终字符串输入_text=current.getText();
holder.note_text.setText(输入_text);
holder.tag_view.setText(文本);
close()数据库;
//holder.tagCircle.setColor(Color.parseColor(“#”+col));
//holder.tagCircle.setColor(标签颜色)*/
}
@凌驾
public int getItemCount(){
返回data.size();
}
/*从回收器视图编辑项目*/
公共无效恢复项(项模型项,int位置){
数据。添加(位置、项目);
(位置);
}
/*声明并初始化NoteListHolder类*/
类NoteListHolder扩展了RecyclerView.ViewHolder{
私有文本视图注释文本、标记视图;
公共相对Yout viewBackground、viewForeground;
字符串注释\u txt\u str;
线性布局添加标签;
按钮标签组;
公共梯度可绘制标记圈;
公共NoteListHolder(查看项目视图){
超级(项目视图);
note\u text=itemView.findviewbyd(R.id.note\u text);
viewBackground=itemView.findViewById(R.id.view\u background);
viewForeground=itemView.findViewById(R.id.view\u前台);
tag\u view=itemView.findviewbyd(R.id.tag\u view);
tagCircle=(GradientDrawable)标记_视图.getBackground();
viewForeground.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
int pos=getAdapterPosition();
note_id=data.get(pos.getId();
日志d(“注释id”,“注释id”+注释id);
Bundle b=新Bundle();
b、 putString(“note_id”,note_id);
编辑_对话框();
}
});
}
私有无效编辑_对话框(){
AlertDialog.Builder=新建AlertDialog.Builder(上下文);
builder.setView(R.layout.notedilog);
建造商名称(“编辑注释”);
//alert_dialog=builder.create();
alert_dialog=builder.show();
警报_dialog.show();
et_get_text=alert_dialog.findviewbyd(R.id.txtNote);
sub\u recycler=alert\u dialog.findviewbyd(R.id.recycler\u dialog);
add_tag=alert_dialog.findviewbyd(R.id.add_tag);
添加_tag.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
AlertDialog.Builder=新建AlertDialog.Builder(上下文);
builder.setView(R.layout.tag_对话框);
builder.setTitle(“选择标签”);
//tag_alert_dialog=builder.create();
tag_alert_dialog=builder.show();
tag_alert_dialog.getWindow().setGravity(Gravity.BOTTOM);
tag_alert_dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_父项,WindowManager.LayoutParams.WRAP_内容);
标记警报对话框。显示();
tag\u important=tag\u alert\u dialog.findviewbyd(R.id.tag\u imp);
tag_food=tag_alert_dialog.findviewbyd(R.id.tag_food);
tag\u enterain=tag\u alert\u dialog.findViewById(R.id.tag\u enterain);
tag\u normal=tag\u alert\u dialog.findviewbyd(R.id.tag\u normal);
tag\u health=tag\u alert\u dialog.findviewbyd(R.id.tag\u health);
tag\u transport=tag\u alert\u dialog.findviewbyd(R.id.tag\u transport);
tag\u study=tag\u alert\u dialog.findviewbyd(R.id.tag\u study);
tag\u services=tag\u alert\u dialog.findviewbyd(R.id.tag\u services);
tag\u shopping=tag\u alert\u dialog.findviewbyd(R.id.tag\u shop);
tag\u progress=tag\u alert\u dialog.findviewbyd(R.id.tag\u progress);
tag\u watchlist=tag\u alert\u dialog.findViewById(R.id.tag\u watchlist);
tag\u set=tag\u alert\u dialog.findviewbyd(R.id.set\u tag);
tag_important.setOnClickListener(这个);
tag_food.setOnClickListener(这个);
tag_enterain.setOnClickListener(此);
android:clickable="true"
android:focusable="true"
public class NoteListAdapter extends RecyclerView.Adapter<NoteListAdapter.NoteListHolder>{
private Context context;
private LayoutInflater inflater;
private ItemModel current;
public List<ItemModel> data;
SubListAdapter adapter;
NoteListHolder holder;
String get_text;
EditText et_get_text;
AlertDialog alert_dialog, tag_alert_dialog;
String id;
LinearLayout tag_important, tag_study, tag_progress, tag_normal, tag_watchlist, tag_shopping, tag_food,tag_enterain,
tag_transport, tag_services, tag_health;
TextView set_date;
String tag_text, tag_color;
private List<TagsModel> tagList;
String note_id;
RecyclerView sub_recycler;
/* constructor */
public NoteListAdapter(Context context, List<ItemModel> data) {
inflater = LayoutInflater.from(context);
this.context = context;
this.data = data;
}
/* notify on item delete */
public void removeItem(int position) {
data.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}
/* delete all items */
public void removeAll() {
data.clear();
notifyDataSetChanged();
}
@Override
public NoteListAdapter.NoteListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View rootView = inflater.inflate(R.layout.note_recycler, parent, false);
holder = new NoteListHolder(rootView);
return holder;
}
@Override
public void onBindViewHolder(NoteListAdapter.NoteListHolder holder, int position) {
current = data.get(position);
// tag_current = tag_data.get(position);
String note_id = data.get(position).getId();
Log.d("note_idm","note id "+note_id);
ListNoteDataBase dataBase = new ListNoteDataBase(context);
dataBase.open();
dataBase.inserttags("abc ", note_id, "ef1232");
tagList = dataBase.getTagList(note_id);
String text = tagList.get(position).getTag();
String col = tagList.get(position).getTag_color();
final String input_text = current.getText();
holder.note_text.setText(input_text);
holder.tag_view.setText(text);
dataBase.close();
// holder.tagCircle.setColor(Color.parseColor("#" + col));
//holder.tagCircle.setColor(tag_color);*/
}
@Override
public int getItemCount() {
return data.size();
}
/* edit item from recycler view */
public void restoreItem(ItemModel item, int position) {
data.add(position, item);
notifyItemInserted(position);
}
/* declare and initialize NoteListHolder class*/
class NoteListHolder extends RecyclerView.ViewHolder{
private TextView note_text, tag_view;
public RelativeLayout viewBackground, viewForeground;
String note_txt_str;
LinearLayout add_tag;
Button tag_set;
public GradientDrawable tagCircle;
public NoteListHolder(View itemView) {
super(itemView);
note_text = itemView.findViewById(R.id.note_text);
viewBackground = itemView.findViewById(R.id.view_background);
viewForeground = itemView.findViewById(R.id.view_foreground);
tag_view = itemView.findViewById(R.id.tag_view);
tagCircle = (GradientDrawable) tag_view.getBackground();
viewForeground.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
note_id = data.get(pos).getId();
Log.d("note_id", "note id " + note_id);
Bundle b = new Bundle();
b.putString("note_id", note_id);
edit_dialog();
}
});
}
private void edit_dialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(R.layout.notedialog);
builder.setTitle("Edit Note");
// alert_dialog = builder.create();
alert_dialog = builder.show();
//alert_dialog.show();
et_get_text = alert_dialog.findViewById(R.id.txtNote);
sub_recycler = alert_dialog.findViewById(R.id.recycler_dialog);
add_tag = alert_dialog.findViewById(R.id.add_tag);
add_tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(R.layout.tag_dialog);
builder.setTitle("Select Tag");
//tag_alert_dialog = builder.create();
tag_alert_dialog = builder.show();
tag_alert_dialog.getWindow().setGravity(Gravity.BOTTOM);
tag_alert_dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
//tag_alert_dialog.show();
tag_important = tag_alert_dialog.findViewById(R.id.tag_imp);
tag_food = tag_alert_dialog.findViewById(R.id.tag_food);
tag_enterain = tag_alert_dialog.findViewById(R.id.tag_enterainment);
tag_normal = tag_alert_dialog.findViewById(R.id.tag_normal);
tag_health = tag_alert_dialog.findViewById(R.id.tag_health);
tag_transport = tag_alert_dialog.findViewById(R.id.tag_transport);
tag_study = tag_alert_dialog.findViewById(R.id.tag_study);
tag_services = tag_alert_dialog.findViewById(R.id.tag_services);
tag_shopping = tag_alert_dialog.findViewById(R.id.tag_shop);
tag_progress = tag_alert_dialog.findViewById(R.id.tag_progress);
tag_watchlist = tag_alert_dialog.findViewById(R.id.tag_watchlist);
tag_set = tag_alert_dialog.findViewById(R.id.set_tag);
View.OnClickListener listener=new View.OnClickListener(){
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.tag_imp:
tag_text = "Important";
tag_color = "C61F2B";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_progress:
tag_text = "Progress";
tag_color = "A50CE2";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_study:
tag_text = "Study";
tag_color = "FCA81D";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_watchlist:
tag_text = "Watchlist";
tag_color = "F4C664";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_normal:
tag_text = "Normal";
tag_color = "10CAC5";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_shop:
tag_text = "Shopping";
tag_color = "15B412";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_food:
tag_text = "Food & Drinks";
tag_color = "F15696";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_enterainment:
tag_text = "Entertainment";
tag_color = "A3128E";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_transport:
tag_text = "Transportation";
tag_color = "3324BD";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_services:
tag_text = "Services";
tag_color = "#F3C861";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
case R.id.tag_health:
tag_text = "Health";
tag_color = "EC4A3A";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
default:
tag_text = "";
tag_color = "ffffff";
appDatabase.updateTags(tag_text, tag_id, tag_color);
appDatabase.close();
break;
}
}
};
tag_important.setOnClickListener(listener);
tag_food.setOnClickListener(listener);
tag_enterain.setOnClickListener(listener);
tag_normal.setOnClickListener(listener);
tag_health.setOnClickListener(listener);
tag_transport.setOnClickListener(listener);
tag_study.setOnClickListener(listener);
tag_services.setOnClickListener(listener);
tag_shopping.setOnClickListener(listener);
tag_progress.setOnClickListener(listener);
tag_watchlist.setOnClickListener(listener);
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
tagList = appDatabase.getTagList(note_id);
String tag_id = tagList.get(getAdapterPosition()).getTagId();
tag_set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// if (tag_alert_dialog.isShowing()) {
tag_alert_dialog.hide();
//}
}
});
}
});
final EditText et_sub_txt = alert_dialog.findViewById(R.id.et_subNote);
ImageButton sub_action = alert_dialog.findViewById(R.id.action_done);
sub_action.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String sub_text_str = et_sub_txt.getText().toString();
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
appDatabase.insertsubnotes(sub_text_str, note_id);
appDatabase.close();
subNote_adapter();
et_sub_txt.getText().clear();
et_sub_txt.clearFocus();
}
});
subNote_adapter();
set_date = alert_dialog.findViewById(R.id.creation_date);
String get_date = data.get(getAdapterPosition()).getDate();
set_date.setText(get_date);
String show_dia_text = data.get(getAdapterPosition()).getText();
id = data.get(getAdapterPosition()).getId();
//set_date.setText((CharSequence) update_date);
/*set cursor position */
note_txt_str = note_text.getText().toString();
et_get_text.setText(note_txt_str);
int position = show_dia_text.length();
et_get_text.setSelection(position);
Button button_edit_done = alert_dialog.findViewById(R.id.edit_note);
button_edit_done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
get_text = et_get_text.getText().toString().trim();
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
appDatabase.updateNotes(get_text, id);
appDatabase.close();
note_text.setText(get_text);
if (alert_dialog.isShowing()) {
alert_dialog.dismiss();
}
}
});
setOnDoneButton();
}
private void setOnDoneButton() {
et_get_text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
get_text = et_get_text.getText().toString().trim();
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
appDatabase.updateNotes(get_text, id);
appDatabase.close();
note_text.setText(get_text);
if (alert_dialog.isShowing()) {
alert_dialog.dismiss();
}
}
return false;
}
});
}
private void subNote_adapter() {
// recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL,false));
// recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
sub_recycler.setLayoutManager(new GridLayoutManager(context, 1));
ListNoteDataBase appDatabase = new ListNoteDataBase(context);
appDatabase.open();
adapter = new SubListAdapter(context, appDatabase.getSubList(note_id));
sub_recycler.setAdapter(adapter);
adapter.notifyDataSetChanged();
appDatabase.close();
}
}