[Android] When you click the button, save the value of EditText to DB and import it into ListView

Asked 2 years ago, Updated 2 years ago, 70 views

     button_insert.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            input_name = (EditText) findViewById(R.id.input_Name);
            input_phoneno = (EditText) findViewById(R.id.input_PhoneNo);

            ContentValues values = new ContentValues();
            values.put("Name", input_name.getText().toString());
            values.put("PhoneNo", input_phoneno.getText().toString());
            myDB.insert("members", null, values);
        }
    });

I wrote it like this in the onCreate() method, but the program ends when I click the button ㅠ<

Could you tell me how to solve it?

Even if you don't write it in code, I think it will be very helpful if you answer it in writing!

android edittext database listview

2022-09-21 14:47

2 Answers

I'm not sure how the db interface is implemented, but I don't think it's common to inflate it with findViewById when you click on it

I don't know if there's an error in inflating the edit text with View onClick. I'm just guessing because I didn't see the error log;;


2022-09-21 14:47

It could be related to Thread management. Check if there is any impact when calling insert from DB.


2022-09-21 14:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.