如何在按钮单击时对齐EditText

时间:2016-02-17 02:37:12

标签: java android

我是Java的新手,所以对任何不正确的术语表示道歉。我有以下代码引用两个按钮并将其对应EditText。如何在按钮点击时将EditText对齐到右边?

我尝试过setTextAlignment但收到cannot resolve symbol错误。

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Creating button references for the buttons corresponding to their IDs through findViewById
        Button rB = (Button) findViewById(R.id.rButton);
        Button lB = (Button) findViewById(R.id.lButton);
        //Register click event with first button
        rB.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                EditText editText = (EditText) findViewById(R.id.editText);//Correspond the text view to its ID
                //Align edittext to the right
            }
        });
        //Register click event with second button
        lB.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                EditText editText = (EditText) findViewById(R.id.editText); //Correspond the text view to its ID
                //Align edittext to the left
            }
        });
    }

0 个答案:

没有答案