displaying a string on the textview when clicking a button in android

后端 未结 9 1969
情深已故
情深已故 2020-12-10 08:43

I\'m very new to Android development and just started to study.

What I\'m trying is to add a button and when that button is pressed a text \"my first project\" to ge

相关标签:
9条回答
  • 2020-12-10 09:15
    public void onCreate(Bundle savedInstanceState) 
    {
        setContentView(R.layout.main);
        super.onCreate(savedInstanceState);
    
        mybtn = (Button)findViewById(R.id.mybtn);
        txtView=(TextView)findViewById(R.id.txtView);
    
        mybtn .setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                txtView.SetText("Your Message");
            }
        });
    }
    
    0 讨论(0)
  • 2020-12-10 09:20

    you use this as txtView.setText("hello");

    0 讨论(0)
  • 2020-12-10 09:24

    Try this

    public void onClick(View view){
        txtView.setText("hello");
    
        //printmyname();
        Toast.makeText(NameonbuttonclickActivity.this, "hello", Toast.LENGTH_LONG).show();
    }
    

    Also in toast use "Hello"

    0 讨论(0)
提交回复
热议问题