我已经为An Edittext变量设置了一个标签。我想在文本TextWatcher afterTextChanged方法中获取该标签。但是有一个可编辑的参数而不是Edittext。
这是我的代码.....
EditText filled = new EditText(DamageCount.this);
filled.setId(100);
filled.setTag(5);
我希望在
中获取该标记@Override
public void afterTextChanged(Editable s) {
}
这种方法
------被修改---------------- 我的整个java类
public class DamageCount extends Activity {
private Button button_next;
static TableLayout tl = null;
private DbWorker dbworker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_damage_count);
DamageCount.this
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
button_next = (Button) findViewById(R.id.button_next);
tl = (TableLayout) findViewById(R.id.show_competitor_product);
dbworker = new DbWorker(this);
Static_Values.arrayListdam_no = new ArrayList<DamegeItemSerialNoModel>();
button_next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/*Intent new_one = new Intent(DamageCount.this,
Invoice_or_prev.class);
startActivity(new_one);
finish();*/
for(DamegeItemSerialNoModel dmmm :Static_Values.arrayListdam_no)
{
System.out.println("Item id is "+dmmm.getItem_id()+" serial no is "+dmmm.getSerial_no());
}
}
});
Cursor cur_products= dbworker.getAllProduct();
int i=0;
if(cur_products.moveToFirst())
{
do{
i++;
// Static_Values.item.put(, value)
add_tbl_row(i,cur_products.getString(3),cur_products.getString(1));
}
while(cur_products.moveToNext());
}
else {
}
cur_products.close();
}
public void add_tbl_row(int value, String name, String tag) {
Static_Values.damaged_id=tag;
TableRow new_row = new TableRow(DamageCount.this);
System.out.println(Static_Values.damaged_id+" id bbb");
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher);
new_row.addView(imageView);
TextView size = new TextView(DamageCount.this);
size.setId(1);
size.setText(name);
size.setPadding(5, 5, 5, 5);
new_row.addView(size);
EditText filled = new EditText(DamageCount.this);
filled.setId(100 * value);
filled.setTag(tag);
filled.setHint("Enter Damaged");
filled.setInputType(InputType.TYPE_CLASS_NUMBER);
new_row.addView(filled);
filled.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
// Toast.makeText(DamageCount.this, s.toString(), Toast.LENGTH_SHORT).show();
if(s.toString().equals("")==false)
{
final LinearLayout layout = new LinearLayout(DamageCount.this);
layout.setOrientation(LinearLayout.VERTICAL);
Button dialogButton = new Button(DamageCount.this);
dialogButton.setText("Add");
// dialogButton.setBackgroundColor(R.drawable.yellobutton);
Static_Values.num_of_serials=Integer.parseInt(s.toString());
for(int i=1;i<Integer.parseInt(s.toString())+1;i++)
{
EditText serial = new EditText(DamageCount.this);
serial.setId(33*i);
serial.setHint("Enter serial");
layout.addView(serial);
}
layout.addView(dialogButton);
final Dialog dialog = new Dialog(DamageCount.this);
dialog.setContentView(layout);
dialog.setTitle("Serial Numbers");
dialog.getWindow().setTitleColor(Color.BLUE);
// set the custom dialog components - text, image and button
// dialog.setContentView(filled);
// dialog.getOwnerActivity().setContentView(filled);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 1; i < Static_Values.num_of_serials+1; i++) {
View vv = dialog.findViewById(33*i);
EditText et=(EditText)vv;
System.out.println(et.getText().toString());
DamegeItemSerialNoModel dism = new DamegeItemSerialNoModel();
dism.setItem_id(Static_Values.damaged_id);
System.out.println(Static_Values.damaged_id);
dism.setSerial_no(et.getText().toString());
Static_Values.arrayListdam_no.add(dism);
}
Static_Values.num_of_serials = 0;
dialog.dismiss();
}
});
dialog.show();
}
}
});
tl.addView(new_row, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
}
答案 0 :(得分:3)
在Textwatcher类中创建一个构造函数,并将edittext传递给int。
public class MyTextWatcher implements TextWatcher
{
private transient EditText editText = null;
public MyTextWatcher(EditText editText)
{
super();
this.editText = editText;
}
@Override
public void afterTextChanged(Editable arg0)
{
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
// TODO Auto-generated method stub
}
}
答案 1 :(得分:0)
如果您想将Editable
转换为简单文字行(String
),请在您的方法中使用此功能:
@Override
public void afterTextChanged(Editable s) {
String str = s.toString();
}