Akshay
Akshay

Reputation: 2534

How to use dynamically created button for saving information to the database

I have to create button dynamically and use that button to save certain information to the database. I want to know that how can i do this.Plz explain with example.

Upvotes: 0

Views: 256

Answers (1)

George
George

Reputation: 1327

Simply. You can use this to create the Button dynamically.

LinearLayout line = (LinearLayout) findViewById(R.id.line);
Button btn = new Button(this);
btn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        /*here is your code to save your info into database*/
    }
});
btn.setText("Save");
line.addView(btn);

Next, if you want to use SqLite you can create own class DBAdapter. Use this link to understand this http://www.devx.com/wireless/Article/40842/1954

or this

http://www.codeproject.com/KB/android/AndroidSQLite.aspx.

There are so much information about this in Google.

Upvotes: 1

Related Questions