Tariq Ziad Tariq Ziad - 21 days ago 8
Android Question

Methods in main activity are showing never used arror

These two methods

addUser()
and
viewDetails()
methods are not being used in this my main activity file. I could find the reason, I don't know where do I have to call them. I am using Android Studio.

public class MainActivity extends AppCompatActivity {

EditText userName, password;

DatabaseAdapter databaseHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

userName = (EditText) findViewById(R.id.editTextUser);
password = (EditText) findViewById(R.id.editTextPass);
databaseHelper = new DatabaseAdapter(this);
}

public void addUser(View view) {

String user = userName.getText().toString();
String pass = password.getText().toString();

long id = databaseHelper.insertData(user, pass);
if (id < 0) {
Message.message(this, "Unsuccessful");
} else {
Message.message(this, "Successful");
}
}

public void viewDetails(View view) {
String data = databaseHelper.getAllData();
Message.message(this, data);
}
}

Answer

After watching this code you are only declaring a function and give the definition of the function you are not using it or calling it .. any where that's why android studio show you not using this method's... You can call this method like addUser(); or viewDetails();

Comments