-3

I have set a tag to An Edittext variable.i want get that tag inside text TextWatcher afterTextChanged method.but there is a Editable parameter not Edittext.

here is my code.....

EditText filled = new EditText(DamageCount.this);
        filled.setId(100);
        filled.setTag(5);

and i want get that tag in

@Override
    public void afterTextChanged(Editable s) {
}

this method

------Edited---------------- my whole java class

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));

    }



}
4
  • why don't you use filled.getTag() then ? May 23, 2014 at 5:17
  • no i cant that Edittext in a different method and i implement that textwatcher class May 23, 2014 at 5:19
  • declare it globally and make it public static if your TextWatcher is in different class. May 23, 2014 at 5:22
  • i think most of you guys misunderstood my question so i decided to provide my whole class May 23, 2014 at 5:43

2 Answers 2

5

Create a constructor in yout Textwatcher class and pass the editext to it.

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
}
}
0

If you want to convert Editable to simple text line (String), use this in your method:

@Override
public void afterTextChanged(Editable s) {
    String str = s.toString();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.