Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 文本视图大小需要根据用户的不同而改变';编辑文本中的给定值_Java_Android - Fatal编程技术网

Java 文本视图大小需要根据用户的不同而改变';编辑文本中的给定值

Java 文本视图大小需要根据用户的不同而改变';编辑文本中的给定值,java,android,Java,Android,根据用户输入动态更改TextView大小。如果用户更改值,textview需要更改 et0=(EditText)findViewById(R.id.EditText0); bt = (Button)findViewById(R.id.btn); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClic

根据用户输入动态更改TextView大小。如果用户更改值,
textview
需要更改

     et0=(EditText)findViewById(R.id.EditText0);
     bt = (Button)findViewById(R.id.btn);

     bt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String text = ((et.getText().toString()));
                    float i=et0.getTextSize();

                    tv.setText(text);
                    tv.setTextSize(i) ; 
        }
    }

//problem is value is changing one time if edit again text size is not changing
any help advance thanks

尝试设置一个变量,以便它接受用户提供的任何内容,并使用该值作为其设置的文本大小。这有意义吗

解决问题的一种方法是在编辑文本框中附加一个侦听器

下面是一个示例实现:

edittext.addTextChangedListener(new TextWatcher() {

   public void onTextChanged(CharSequence s, int start, int before,
        int count) {
       if(!s.equals("") )
            { //do your work here }
       }

   }

   public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {

   }

   public void afterTextChanged(Editable s) {

   }
});

您可以在
onTextChanged
内进行小尺寸检查。一旦到达某个断点,您将增加文本的大小。:-)

要将
文本视图
文本大小更改为
编辑文本
输入值,请使用以下命令:

 bt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String text = ((et.getText().toString()));  //number input

                    Float f= Float.parseFloat(text);  // setting the input number as textview text size
                    tv.setText(text);
                    tv.setTextSize(f) ; 
        }
    }
注意:
editText
输入值必须是xml中的数字

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/edtText"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/txtOutput"/>

单击此处的按钮,您的textview文本大小将设置为等于您的edittext文本大小。你到底想要什么?请再解释一下。我有两个编辑文本框用户在第一个编辑文本框中输入文本ex:“ABCD”大小ex:18文本视图文本大小需要调整,需要在另一个编辑文本中输入18,以便文本视图根据用户输入显示文本在这种情况下,请参见下面的答案。过程:com.example.chetan.ninepatchimages,PID:4372 java.lang.NumberFormatException:无效浮点:java.lang.StringToReal.invalidReal(StringToReal.java:63)处的“fyuu”使用两个edittext,一个用于文本,另一个用于文本大小。在文本大小编辑文本中,只输入数字,否则会发现相同的错误。NumberFormateException第1版文本有一个值“ABC”第二次我传递文本大小例如:“10”按钮单击文本视图显示ABC,如果我再次将15更改为20“ABC”,则该大小应为15。请将文本视图的大小更改为20see 2编辑文本框一个我正在输入文本“ABC”另一个我正在输入“15”按钮单击文本视图大小需要更改15以显示在文本视图中的ABC,文本视图需要显示ABC,ABC大小应为15,如果将值15更改为20,“ABC”大小需要更改againet=(EditText)findViewById(R.id.EditText);et0=(EditText)findViewById(R.id.EditText0);bt=(按钮)findviewbyd(R.id.btn);tv=(TextView)findViewById(R.id.text);bt.setOnClickListener(new View.OnClickListener(){@Override public void onClick(View v){String gttext=((et.getText().toString());int s=Integer.parseInt(et0.getText().toString().trim());tv.setText(gttext);tv.setTextSize(s);});
      edtText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                txtOutput.setText(charSequence.toString());
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });