繁体   English   中英

我想在Android中为6个edittext框制作函数,其中包括edittext的所有属性,以便我可以简单地调用function

[英]i want to make function for 6 edittext boxes in android which includes all properties of edittext so that i can just simply call function

我有6个edittext框,我想为这6个edittext框创建一个函数,这样我就可以简单地调用该函数,而不必一直定义edittext框。 这是edittext框的d代码....

TableLayout t1=(TableLayout)findViewById(R.id.table_layout01);
                TableRow tr1=new TableRow(inventory.this);
                tr1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

                EditText ed6=new EditText(inventory.this);
                ed6.setTextColor(Color.BLACK);
                ed6.setText("1");

                tr1.addView(ed6);

                EditText ed7=new EditText(inventory.this);
                ed7.setTextColor(Color.BLACK);
                ed7.setText("2");

                tr1.addView(ed7);

                EditText ed8=new EditText(inventory.this);
                ed8.setTextColor(Color.BLACK);
                ed8.setText("3");

                tr1.addView(ed8);.............(3 more edittext same like these)

进行for循环并在该循环中编写添加到tr1代码中的edittext

 for(int i=0;i<7;i++)
    {
TableRow tr1=new TableRow(this);
    EditText ed7=new EditText(inventory.this); 
      ed7.setTextColor(Color.BLACK);     
       String s=new Integer(i).toString();      //convert the integer into String   
       ed7.setText(s); 
tr1.addView(ed7);
 <TableLayoutName>.addview(tr1);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM