My question has three parts.
My Layout consists of 26 Buttons: ButtonA, ButtonB, ButtonC…ButtonZ
The buttons are arranged in order on the screen. When the button is clicked I want to capture the click event and filter a SQLiteDB of words by the first letter that was clicked.
How do I write the minimum amount of code that will capture the click, identify the button’s corresponding letter, and return the letters that begin with the selected letter from the SQLite Database?
Below is my code that has not been optimized for code brevity.
//Create your buttons and set their onClickListener to "this"
Button b1 = (Button) findViewById(R.id.Button04);
b1.setOnClickListener(this);
Button b2 = (Button) findViewById(R.id.Button03);
b2.setOnClickListener(this);
//implement the onClick method here
public void onClick(View v) {
// Perform action on click
switch(v.getId()) {
case R.id.Button04:
//Toast.makeText(this,"test a",Toast.LENGTH_LONG).show();
// Do the SqlSelect and Listview statement for words that begin with "A" or "a" here.
break;
case R.id.Button03:
//Toast.makeText(this,"test b",Toast.LENGTH_LONG).show();
// Do the SqlSelect and Listview statement for words that begin with "A" or "a" here.
break;
}
}
If you have lots of characters and a button for each character, I would probably extend the “BaseAdapter” class and make a ButtonAdapter holding the alphabet as a character array, instead of actually making 28:ish buttons… …if I understood the problem correctly?
The getView could look something like this: