版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jian11058/article/details/84773262
这是一个自定义弹出框
public void showReNameWindow(TextView tv_location,int Location){
View contentview = LayoutInflater.from(context).inflate(R.layout.rewrite_name_popwin, null);
edt=contentview.findViewById(R.id.pop_rewrite_edt);
TextView tv_size=contentview.findViewById(R.id.pop_rewrite_tv_size);
TextWatcher mTextWatcher = new TextWatcher() {
private CharSequence temp;
private int editStart ;
private int editEnd ;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
temp = s;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
// mTextView.setText(s);//将输入的内容实时显示
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
editStart = edt.getSelectionStart();
editEnd = edt.getSelectionEnd();
tv_size.setTextColor(R.color.text_grey);
tv_size.setText(temp.length() + "/100");
if (temp.length() > 100) {
s.delete(editStart-1, editEnd);
int tempSelection = editStart;
tv_size.setTextColor(Color.RED);
tv_size.setText(temp.length() + "/100");
edt.setSelection(tempSelection);
}
}
};
edt.addTextChangedListener(mTextWatcher);
TextView tv=contentview.findViewById(R.id.pop_rewrite_tv);
TextView tv_enter=contentview.findViewById(R.id.pop_enterhistory_tv);
tv_enter.setVisibility(View.GONE);
edt.setText(tv_location.getText());
PopupWindow pw = new PopupWindow(contentview, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (TextUtils.isEmpty(edt.getText())){
Toast.makeText(context,"名称不能为空",Toast.LENGTH_SHORT).show();
}else {
RewriteData(qipanJiluAcitivity.getId(Location), edt.getText().toString());
tv_location.setText(edt.getText());//将按钮设置为当前,是不是需要重新获取列表。
list.set(Location, tv_location.getText().toString());
listData.set(Location, tv_location.getText().toString());
pw.dismiss();
}
}
});
//当保存数据操作时,则其他变量应该修改为成员变量,要不然,第一遍弹出框没错,第二次框弹出就会出错
pw.showAsDropDown(tv_location);
}