How to get text from EditText?

前端 未结 7 1944
旧时难觅i
旧时难觅i 2021-01-01 12:21

The question is quite simple. But I want to know where exactly do we make our references to the gui elements? As in which is the best place to define:

final          


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 12:38

    Put this in your MainActivity:

    {
        public EditText bizname, storeno, rcpt, item, price, tax, total;
        public Button click, click2;
        int contentView;
    
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate( savedInstanceState );
            setContentView( R.layout.main_activity );
            bizname = (EditText) findViewById( R.id.editBizName );
            item = (EditText) findViewById( R.id.editItem );
            price = (EditText) findViewById( R.id.editPrice );
            tax = (EditText) findViewById( R.id.editTax );
            total = (EditText) findViewById( R.id.editTotal );
            click = (Button) findViewById( R.id.button );
        }
    }
    

    Put this under a button or something

    public void clickBusiness(View view) {
        checkPermsOfStorage( this );
    
        bizname = (EditText) findViewById( R.id.editBizName );
        item = (EditText) findViewById( R.id.editItem );
        price = (EditText) findViewById( R.id.editPrice );
        tax = (EditText) findViewById( R.id.editTax );
        total = (EditText) findViewById( R.id.editTotal );
        String x = ("\nItem/Price: " + item.getText() + price.getText() + "\nTax/Total" + tax.getText() + total.getText());
        Toast.makeText( this, x, Toast.LENGTH_SHORT ).show();
        try {
            this.WriteBusiness(bizname,storeno,rcpt,item,price,tax,total);
            String vv = tax.getText().toString();
            System.console().printf( "%s", vv );
            //new XMLDivisionWriter(getString(R.string.SDDoc) + "/tax_div_business.xml");
        } catch (ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }
    

    There! The debate is settled!

提交回复
热议问题