开发者

Text box + submit button how do i send the string to another class

开发者 https://www.devze.com 2023-02-17 23:10 出处:网络
I am trying to crea开发者_如何转开发te a class that allows search of a database to do this i am creating these classes.

I am trying to crea开发者_如何转开发te a class that allows search of a database to do this i am creating these classes.

  • Search - search has a text box and a submit button. on submit it should send the text to DB.
  • DB - DB handles the database connection and gets the result using the string it receives.
  • Result - result will have a list activity view that will display the results revived from DB.

Thats how i want it to work.

At the moment i have this code.... and not much of it is working so i was hoping someone can tell me if im doing it wrong.

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);

        confirm = (Button) findViewById(R.id.confirm);
        search = (EditText) findViewById(R.id.search);

        confirm.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                String   mSearch = search.getText().toString();

                trySearch(mSearch);
            }
        });
    }

how do i pass the mSearch string to my DB class, and run the method trySearch


If you want to process the search string in your DB class, then simply use a setter/ getter system for this. Either link the butoon to the DB class using a get method that reads the content out of your textbox, or let the button set a parameter in your DB class.

Personally, I would let the DB class get the string on click.


Add this (where MyDatabaseClass is your database class name):

MyDatabaseClass mdc = new MyDatabaseClass();

Then do

mdc.trySearch(mSearch);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号