-3

[enter image description here][1]This is my first android studio project. Unable to invoke the Button class despite import the widget.Button package. Pl guide.[Main activity screen shot.[][2

  • You will find your answer here : [How to handle button click][1] [1]: https://stackoverflow.com/a/14783194/5424676 – Omar Beshary Apr 08 '18 at 13:02
  • You will find your answer here : [How to handle button click][1] [1]: https://stackoverflow.com/a/14783194/5424676 – Omar Beshary Apr 08 '18 at 13:06
  • Your question is unclear. Are you asking how to handle a button click? `Button btn = (Button) findViewById(R.id.btn); clickButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { **Do what you want with the click here** } });` – Abhi Apr 08 '18 at 15:29

1 Answers1

0

I guess by button class you mean the action once the button has been clicked. First step: Add OnClick on XML Second step: Call the name of activity in Java class Third step: Write the action to be taken OnClick.

  • Thanks much. My issue is even before that stage. in the MainActivity.kt, i have imported the android.widget.Button package. When the following code is written for creation of Button object: Button obj = ....... I get an error message prompting ---- Function Invocation 'Button(....)' expected. It states none of the functions can be called with the arguments supplied. pl guide. – Sudhakar Vijayasarathy Apr 08 '18 at 13:03
  • Do not add pictures of code. Instead copy your code and paste it as text. – Abhi Apr 08 '18 at 13:07
  • package com.example.sudhakarvijayasarathy.firsttest.feature import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.widget.Button class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) Button btn = (Button) findViewById(R.id.button) } } – Sudhakar Vijayasarathy Apr 08 '18 at 13:13