Get text of view (button)

◇◆丶佛笑我妖孽 提交于 2019-12-07 11:19:41

问题


I have two column in relative layout. both column have few button with text. I want to draw a line using finger which join the button. Take the example of "match the following"
like A ------------------- A.

Above things are done. Now i want to get the text of button from where user start drawing the line and end the line. In above case is "A".

Could any one please help me out.

I want to get the text with Orange circle when user start drawing the line from finger and then text of the green circle when user stop the line draw from finger. Text showing inside the circle are button only.

I am using onTouchEvent(MotionEvent event) for drawing line.

I hope now i am able to explain my requirement more

Thanks


回答1:


    public void onClick(View v) {

        Button b = (Button)v;
        String buttonText = b.getText().toString();
        Toast.makeText(getBaseContext(), buttonText , 1000).show();
    }



回答2:


for example, if the View contains text, use this:

( (TextView) view ).getText().toString();

where "view" is being cast to TextView.




回答3:


Do you mean you want get the text display by your button in layout file ?

You can do this by a simple

button.getText();


来源:https://stackoverflow.com/questions/20263673/get-text-of-view-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!