Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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_Xml_Android Edittext_Horizontal Scrolling - Fatal编程技术网

Java 使用按钮添加文本时编辑文本水平滚动

Java 使用按钮添加文本时编辑文本水平滚动,java,android,xml,android-edittext,horizontal-scrolling,Java,Android,Xml,Android Edittext,Horizontal Scrolling,我制作了一个简单的按钮,在编辑文本中添加数字“1” 下面是XML代码 <EditText android:id="@+id/edittext1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/button1" android:layout_width="wrap_content"

我制作了一个简单的按钮,在编辑文本中添加数字“1”

下面是XML代码

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

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1"   
    android:onClick="Btn1"
/>
当我用键盘输入编辑文本时,它会自动水平滚动并显示最后一个字符。但当我按下按钮时,它会添加文本,但不会滚动(因此只有第一个字符可见)

有什么解决办法吗?

试试这个:

public void Btn1(View v){
    EditText edittext1 = (EditText) findViewById(R.id.edittext1);
    String getText = edittext1.getText().toString();
    show_results.setText(getText+"1"); // not really sure what show_results is,
                                       // but I suppose it's another EditText
    show_results.setSelection(edittext1.getText().length());
}

您想滚动视图吗???@Naddy它不是一个视图。这是纠正你的基本的伴侣。EditText扩展了扩展视图的TextView。你想滚动编辑文本吗?“我不清楚.”setSelection“:这导致,int)哪个状态“将光标移动到偏移索引”-我可能理解您的问题,但我认为您希望光标位于插入文本的末尾(即使您的编辑文本具有固定高度,视图也将始终滚动-我将答案编辑为特定于模式)
public void Btn1(View v){
    EditText edittext1 = (EditText) findViewById(R.id.edittext1);
    String getText = edittext1.getText().toString();
    show_results.setText(getText+"1"); // not really sure what show_results is,
                                       // but I suppose it's another EditText
    show_results.setSelection(edittext1.getText().length());
}