Android - Retrieve all data from a SQLite table row - android

I have searched and cannot find an answer to my issue so i hope i am not completely barking up the wrong tree (so to speak).
I am new to android and have started to create an app. My app on one screen creates and adds entries to a SQLite database using public class DatabaseHandler extends SQLiteOpenHelper and this all appears to work.
I retrieve all the data and populate it into a grid, again this now works.
My issue is I am unable to retrieve one complete line from the grid.
I populate/display the grid with the following code.
I have cut a lot out as the grid is made in stages, header, blank lines etc but the grid does display as I want.
The id’s work as when I touch a line it displays its unique id.
The onClick is right at the end and when I use getText() instead of getID() all it returns is the data in the labelDate. How do I retrieve all the labels as listed below?
package com.pump.diary;
import java.util.List;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
public class PumpDiaryReview extends Activity implements android.view.View.OnClickListener{
DatabaseHandler db = new DatabaseHandler(this);
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pump_diary_review);
TableLayout tl = (TableLayout) findViewById(R.id.gridview);
boolean doFirstHeadings = true;
String dateCheck = "";
Integer count=0;
List<Readings> readings = db.getAllReadings();
for (Readings re : readings)
{
if (doFirstHeadings == true)
{
//First record so setup the headings.
TableRow tr_head = new TableRow(this);
tr_head.setId(10);
tr_head.setBackgroundColor(Color.GRAY);
tr_head.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TextView label_date = new TextView(this);
label_date.setText("Date:Time");
TextView label_CP = new TextView(this);
label_CP.setText("CP");;
TextView label_BG = new TextView(this);
label_BG.setText("BG");
TextView label_QA = new TextView(this);
label_QA.setText("QA");
TextView label_CN = new TextView(this);
label_CN.setText("CN");
TextView label_KT = new TextView(this);
label_KT.setText("KT");
TextView[] tvHeaderArray = {label_date, label_CP, label_BG, label_QA, label_CN, label_KT};
for (TextView tvHeader : tvHeaderArray)
{
tvHeader.setTextColor(Color.WHITE);
tr_head.addView(tvHeader);
}
tl.addView(tr_head, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
doFirstHeadings = false;
count = 0;
}
// Create the table row
TableRow tr = new TableRow(this);
tr.setClickable(true);
tr.setId(100+count);
tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TextView labelDATE = new TextView(this);
TextView labelCP = new TextView(this);
TextView labelBG = new TextView(this);
TextView labelQA = new TextView(this);
TextView labelCN = new TextView(this);
TextView labelKT = new TextView(this);
TextView[] tvArray = {labelDATE, labelCP, labelBG, labelQA, labelCN, labelKT};
if (!dateCheck.equals(re.getDate()) || (dateCheck == null) || dateCheck == "")
{
//Add a blank line in.
TableRow tr_blank = new TableRow(this);
tr_blank.setId(10);
tr_blank.setBackgroundColor(Color.GRAY);
tr_blank.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TextView label_date = new TextView(this);
label_date.setId(20);
label_date.setText(re.getDate());
label_date.setTextColor(Color.WHITE);
tr_blank.addView(label_date);
tl.addView(tr_blank, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
labelDATE.setText(re.getTime());
labelCP.setText(re.getCP());
labelBG.setText(re.getBG());
labelQA.setText(re.getQA());
labelCN.setText(re.getCN());
labelKT.setText(re.getKT());
for (TextView tv : tvArray)
{
tv.setTextColor(Color.WHITE);
tv.setId(200+count);
tr.setOnClickListener(this);
tr.addView(tv);
}
//add this to the table row
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
dateCheck = re.getDate().toString();
++count;
}
}
public void onClick(View v)
{
if (v instanceof TableRow)
{
TableRow row = (TableRow) v;
TextView child = (TextView) row.getChildAt(0);
Toast toast = Toast.makeText(this, String.valueOf(child.getId()), Toast.LENGTH_SHORT);
toast.show();
}
}
}
I can supply all the code for the grid creation if required.
Thanks for any help.

My issue is I am unable to retrieve one complete line from the grid.
The onClick is right at the end and when I use getText() instead of
getID() all it returns is the data in the labelDate. How do I retrieve
all the labels as listed below?
I'm not certain I understand the question, but this will give you toast with all the ID's in a TableRow
public void onClick(View v) {
if (v instanceof TableRow) {
TableRow row = (TableRow) v;
String msg = "";
for (int i=0; i < row.getChildCount(); i++) {
TextView child = (TextView) row.getChildAt(i);
msg += String.valueOf(child.getId()) + " ";
}
Toast toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
toast.show();
}
}

your problem is here:
TextView child = (TextView) row.getChildAt(0); <------------------
Toast toast = Toast.makeText(this, String.valueOf(child.getId()), Toast.LENGTH_SHORT);
toast.show();
you are specifically requesting the first child of the row and getting the text from it which of course would only yield one value. to get all the rest, i'd suggest going to your List<Readings> and specifying the object that you want by index. then you can just print out everything from the object. As for how you'd get this index...with your current implementation, i think perhaps tagging your textViews with the index as they are being made and being populated by your List might be the most straight-forward.

Related

How can i remove the data of a row with a button click?

After clicking a button my code creates a row in table with a TextView , an EditView and a delete button. The delete button is programmed to delete the row from the table (which successfully does) and the date from a list in Notes.class (which is the problem). To confirm this action i have a text view to count the list size with the dates and when i press the delete button nothing is changed.
Sorry if this is a silly question but i am really new to Android :)
The button handler
public void addButtonHandler(View view) {
TableLayout tl = (TableLayout) findViewById(R.id.subs_table);
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
//get the date in string
String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
//the TextView with the date
TextView tv = new TextView(this);
tv.setText(date);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP , 18);
//editText with the type
final EditText et = new EditText(this);
TableRow.LayoutParams params = new TableRow.LayoutParams(getPx(50), ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(getPx(130),0,getPx(40),0);
et.setLayoutParams(params);
SharedPreferences prefs = getSharedPreferences(SubsPREFERENCES , MODE_PRIVATE); // get notes object
Gson gsonN = new Gson();
String jsonN = prefs.getString("DATES" , "");
final Notes notes = gsonN.fromJson(jsonN , Notes.class);
//button for deleting row
ImageButton imageButton = new ImageButton(this);
TableRow.LayoutParams imageParams = new TableRow.LayoutParams(50,70);
imageParams.setMargins(5 ,0 ,0 ,0);
imageButton.setLayoutParams(imageParams);
imageButton.setImageResource(R.drawable.ok);
imageButton.setClickable(true);
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ViewGroup parent = (ViewGroup) view.getParent();
ViewGroup gradnparent = (ViewGroup) parent.getParent();
gradnparent.removeView(parent);
notes.delete(tv.getText().toString()); // this does not seem to work
}
}
);
// Adding views in row
tr.addView(tv);
tr.addView(et);
tr.addView(imageButton);
// Adding row in table
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT
, TableLayout.LayoutParams.WRAP_CONTENT));
//add info in note
notes.addNote(date , et.getText().toString());
// saving the changes in notes
SharedPreferences sharedPreferences =getSharedPreferences(SubsPREFERENCES ,MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
String json1 = gsonN.toJson(notes);
editor.putString("DATES" , json1);
editor.apply();
//display the number of objects in list
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(String.valueOf(notes.getNum_dates()));
}
The notes class
package com.uni.notes;
public class Notes {
private ArrayList<String> list =new ArrayList<String>();
private ArrayList<String> type =new ArrayList<String>();
public Notes() {}
public int getNum_dates() {return list.size();}
public void addNote(String date ,String typeN) {
list.add(date);
type.add(typeN);
}
public String getDate (int pos){
return list.get(pos);
}
public String getType (int pos) {return type.get(pos);}
public void delete (String thing) {
for (String element : list){
if (element.equals(thing) ){
list.remove(element);
}
}
}
}
Just after
notes.delete(et.getText().toString()); // this does not seem to work
move your textview counting element update :
notes.delete(et.getText().toString()); // this does not seem to work
//display the number of objects in list
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(String.valueOf(notes.getNum_dates()));
This will update the counting Textview rigth after you clicked the delete button.

TableLayout - The specified child already has a parent

I am trying to create a simple table programmatically. But the code crashes when row2.addView is called. With this error:
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Here is my code:
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.contnt_2);
TableLayout tableLayout = new TableLayout(this);
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams();
tableRowParams.setMargins(1, 1, 1, 1);
TableRow row1 = new TableRow(this);
TableRow row2 = new TableRow(this);
TableRow row3 = new TableRow(this);
TextView text1 = new TextView(this);
text1.setText("DDDDDDDDDDDDD");
text1.setBackgroundColor(Color.GRAY);
TextView text2 = new TextView(this);
text2.setText("DDDDDDDDDDDDD");
text2.setBackgroundColor(Color.GRAY);
TextView text3 = new TextView(this);
text3.setText("DDDDDDDDDDDDD");
text3.setBackgroundColor(Color.GRAY);
row1.addView(text1, tableRowParams);
row1.addView(text2, tableRowParams);
row1.addView(text3, tableRowParams);
row2.addView(text1, tableRowParams);
row2.addView(text2, tableRowParams);
row2.addView(text3, tableRowParams);
row3.addView(text1, tableRowParams);
row3.addView(text2, tableRowParams);
row3.addView(text3, tableRowParams);
tableLayout.addView(row1);
tableLayout.addView(row2);
tableLayout.addView(row3);
setContentView(tableLayout);
}
I can't find a reason why it happens. how correctly to add rows to table ? Can you help me out?
This is because you created three TextViews and added them to your first TableRow with this code:
row1.addView(text1, tableRowParams);
row1.addView(text2, tableRowParams);
row1.addView(text3, tableRowParams);
Then tried adding that same TextView that you already created to Row 2.
You can't add the same TextView to multiple TableRows, because as the error says, each TextView can only have one parent.
You need to create three different TextViews for EACH TableRow.
The main problem with your approach: A view can't be a child of more than one parent in Android.
Here's a tutorial on how to create a TableLayout programmatically, maybe you get some ideas for improvements to your logic:
http://www.prandroid.com/2014/05/creating-table-layout-dynamically-in.html
I'll paste it here as well just in case:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] row = { "ROW1", "ROW2", "Row3", "Row4", "Row 5", "Row 6",
"Row 7" };
String[] column = { "COLUMN1", "COLUMN2", "COLUMN3", "COLUMN4",
"COLUMN5", "COLUMN6" };
int rl=row.length; int cl=column.length;
Log.d("--", "R-Lenght--"+rl+" "+"C-Lenght--"+cl);
ScrollView sv = new ScrollView(this);
TableLayout tableLayout = createTableLayout(row, column,rl, cl);
HorizontalScrollView hsv = new HorizontalScrollView(this);
hsv.addView(tableLayout);
sv.addView(hsv);
setContentView(sv);
}
public void makeCellEmpty(TableLayout tableLayout, int rowIndex, int columnIndex) {
// get row from table with rowIndex
TableRow tableRow = (TableRow) tableLayout.getChildAt(rowIndex);
// get cell from row with columnIndex
TextView textView = (TextView)tableRow.getChildAt(columnIndex);
// make it black
textView.setBackgroundColor(Color.BLACK);
}
public void setHeaderTitle(TableLayout tableLayout, int rowIndex, int columnIndex){
// get row from table with rowIndex
TableRow tableRow = (TableRow) tableLayout.getChildAt(rowIndex);
// get cell from row with columnIndex
TextView textView = (TextView)tableRow.getChildAt(columnIndex);
textView.setText("Hello");
}
private TableLayout createTableLayout(String [] rv, String [] cv,int rowCount, int columnCount) {
// 1) Create a tableLayout and its params
TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams();
TableLayout tableLayout = new TableLayout(this);
tableLayout.setBackgroundColor(Color.BLACK);
// 2) create tableRow params
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams();
tableRowParams.setMargins(1, 1, 1, 1);
tableRowParams.weight = 1;
for (int i = 0; i < rowCount; i++) {
// 3) create tableRow
TableRow tableRow = new TableRow(this);
tableRow.setBackgroundColor(Color.BLACK);
for (int j= 0; j < columnCount; j++) {
// 4) create textView
TextView textView = new TextView(this);
// textView.setText(String.valueOf(j));
textView.setBackgroundColor(Color.WHITE);
textView.setGravity(Gravity.CENTER);
String s1 = Integer.toString(i);
String s2 = Integer.toString(j);
String s3 = s1 + s2;
int id = Integer.parseInt(s3);
Log.d("TAG", "-___>"+id);
if (i ==0 && j==0){
textView.setText("0==0");
} else if(i==0){
Log.d("TAAG", "set Column Headers");
textView.setText(cv[j-1]);
}else if( j==0){
Log.d("TAAG", "Set Row Headers");
textView.setText(rv[i-1]);
}else {
textView.setText(""+id);
// check id=23
if(id==23){
textView.setText("ID=23");
}
}
// 5) add textView to tableRow
tableRow.addView(textView, tableRowParams);
}
// 6) add tableRow to tableLayout
tableLayout.addView(tableRow, tableLayoutParams);
}
return tableLayout;
}
}

Building an activity from button click

I build a UI based on JSON Objects sent in a method. Each time the method runs, a new row is added to the UI. I need my chartsButtonListener to be able to access the JSONObject question.
public void buildQuestions(JSONObject question) throws JSONException {
LayoutInflater inflater = (LayoutInflater) getActivity().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
questionContainer = (TableLayout) mainLayout.findViewById(R.id.questionContainer);
View questionBox = inflater.inflate(R.layout.question, null);
questionBox.setId(Integer.parseInt(question.getString("id")));
TextView title = (TextView) questionBox.findViewById(R.id.questionTextView);
title.setText(question.getString("title"));
//omitted code for verbosity
Button chartsButton = (Button) questionBox.findViewById(R.id.chartsButton);
Button submitButton = (Button) questionBox.findViewById(R.id.submitButton);
chartsButton.setOnClickListener(chartsListener);
submitButton.setOnClickListener(submitListener);
TableRow tr = (TableRow) questionBox;
TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT);
trParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(trParams);
LinearLayout progressRow = (LinearLayout) mainLayout.findViewById(R.id.progressRow);
progressRow.setVisibility(View.GONE);
questionContainer.addView(tr);
}
public OnClickListener chartsListener = new OnClickListener() {
public void onClick(View v) {
Intent chart = new Intent();
chart.setClass(getActivity(), Chart.class);
Log.v("", v.getParent().getClass().toString());//returns the TableRow
startActivity(chart);
}
};
I am familiar with put extra, but it would be best if I could simply pass the question object to the listener directly, so I could then forward it along to the Intent. Any suggestions?
You can use View.setTag(Object) to associate any arbitrary object to a View.
chartsButton.setTag(question);
And in your onClick, you can do:
Question q = (Question) v.getTag();

Dynamic rows don't appear

I have a class Store.java where I simply store 2 strings and an integer. Then I create an ArrayList object of the same. I do this so that I can populate the values from 2 spinners and an edit text into the ArrayList dynamically. I want to get these values displayed in a tabular format. Also I've created a subclass of Application so that the ArrayList can be easily updated and retrieved in other Activities. The problem is that when I click on the 'Bill' button the dynamic rows are not added to the table layout.
Here is the relevant code:
(MyApp.java)
public class MyApp extends Application {
ArrayList<store> B = null;
public ArrayList<store> getState(){
return B;
}
public void setState(ArrayList<store> B){
this.B = B;
}
}
(Bill.java)
public class Bill extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.calc);
ArrayList<store> B = new ArrayList<store>();
store temp1=null;
MyApp appState = ((MyApp)getApplicationContext());
appState.setState(B);
B = appState.getState();
TableLayout tl = (TableLayout)findViewById(R.id.myTable);
for(int i=0;i<B.size();i++)
{
temp1=new store();
TableRow tr = new TableRow(this);
tr.setId(100+i);
temp1=B.get(i);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView b = new TextView(this);
b.setId(200+i);
b.setText(temp1.getPizzaName());
TextView b1 = new TextView(this);
b1.setText(temp1.getPizzaSize());
b1.setId(300+i);
TextView b2 = new TextView(this);
b2.setText(String.valueOf(temp1.getQuantity()));
b2.setId(400+i);
b.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(b);
b1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(b1);
b2.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(b2);
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
}
Take a look to your code:
ArrayList<store> B = new ArrayList<store>();
store temp1=null;
MyApp appState = ((MyApp)getApplicationContext());
appState.setState(B);
B = appState.getState();
You create a List, than set it as your state, then retrieve it again.
How do you want to has some data on it?
PS: Please follow the code conventions, you code is hard to read.
Your variable 'temp' is initialized once. You should make a new instance every time before add it to the List.

Onclicklistener for a programmatically created button

I have looked for an answer for this but can't seem to find one.
I have a button that has been created programmatically (rather than in the xml file) and I want something to happen when its clicked, show an alert or move to another screen etc.
Button code:
Button submitButton = new Button(this);
submitButton.setId(99);
submitButton.setText("Submit");
Listener code:
View submitButtonListener = findViewById(99);
submitButtonListener.setOnClickListener(this);
So I have set up the listener to find that button but I get this error
The method setOnClickListener(View.OnClickListener) in the type View
is not applicable for the arguments
(RegisterScreen) RegisterScreen.java /AccessibleApp/src/org/project/accessible line
217 Java Problem
I think it may be something to do with the fact that I don't have setContentView(); at the start of the class because the whole page is written programmatically (because I need to add checkboxes programmatically).
Here is the all the code below if it helps:
public class RegisterScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initiate the database to be qureied
DatabaseData db = new DatabaseData(this);
db = new DatabaseData(this);
try {
db.createDataBase();
}
catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
db.openDataBase();
}
catch(SQLException sqle){
throw sqle;
}
SQLiteDatabase rdb = db.getReadableDatabase();
//main layout of the screen
LinearLayout layoutMain = new LinearLayout(this);
layoutMain.setOrientation(LinearLayout.VERTICAL);
layoutMain.setBackgroundColor(Color.WHITE);
//Linear Layout for the Banner
LinearLayout banner = new LinearLayout(this);
banner.setOrientation(LinearLayout.VERTICAL);
banner.setBackgroundColor(Color.rgb(17, 168, 191));
//layout params for height and width
LayoutParams bannerParams = new android.widget.LinearLayout.LayoutParams(
android.widget.LinearLayout.LayoutParams.FILL_PARENT, 40);
banner.setLayoutParams(bannerParams);
//Banner text
TextView bannerText = new TextView(this);
bannerText.setText("Register");
bannerText.setTextColor(Color.WHITE);
banner.addView(bannerText);
bannerText.setTextSize(24);
bannerText.setGravity(Gravity.CENTER);
//add banner layout to main layout
layoutMain.addView(banner);
//Scroll view for the rest of the screen
ScrollView sv = new ScrollView(this);
//Table layout to align the items register form items
TableLayout tl = new TableLayout(this);
//Table rows to put items on left and right sides of the page
TableRow usernameTR = new TableRow(this);
//Username label
TextView usernameL = new TextView(this);
usernameL.setText("Username:");
usernameL.setTextColor(Color.BLACK);
usernameTR.addView(usernameL);
//Username textbox
EditText usernameTB = new EditText(this);
usernameTB.setWidth(250);
usernameTR.addView(usernameTB);
tl.addView(usernameTR);
TableRow emailTR = new TableRow(this);
//email label
TextView emailL = new TextView(this);
emailL.setText("Email:");
emailL.setTextColor(Color.BLACK);
emailTR.addView(emailL);
//email textbox
EditText emailTB = new EditText(this);
emailTB.setWidth(250);
emailTR.addView(emailTB);
tl.addView(emailTR);
TableRow forenameTR = new TableRow(this);
//forename label
TextView forenameL = new TextView(this);
forenameL.setText("Forename:");
forenameL.setTextColor(Color.BLACK);
forenameTR.addView(forenameL);
//forename textbox
EditText forenameTB = new EditText(this);
forenameTB.setWidth(250);
forenameTR.addView(forenameTB);
tl.addView(forenameTR);
TableRow surnameTR = new TableRow(this);
//surname label
TextView surnameL = new TextView(this);
surnameL.setText("Surname:");
surnameL.setTextColor(Color.BLACK);
surnameTR.addView(surnameL);
//surname textbox
EditText surnameTB = new EditText(this);
surnameTB.setWidth(250);
surnameTR.addView(surnameTB);
tl.addView(surnameTR);
TableRow streetTR = new TableRow(this);
//street label
TextView streetL = new TextView(this);
streetL.setText("Street:");
streetL.setTextColor(Color.BLACK);
streetTR.addView(streetL);
//street textbox
EditText streetTB = new EditText(this);
streetTB.setWidth(250);
streetTR.addView(streetTB);
tl.addView(streetTR);
TableRow postcodeTR = new TableRow(this);
//postcode label
TextView postcodeL = new TextView(this);
postcodeL.setText("Postcode:");
postcodeL.setTextColor(Color.BLACK);
postcodeTR.addView(postcodeL);
//postcode textbox
EditText postcodeTB = new EditText(this);
postcodeTB.setWidth(250);
postcodeTR.addView(postcodeTB);
tl.addView(postcodeTR);
TableRow cityTR = new TableRow(this);
//city label
TextView cityL = new TextView(this);
cityL.setText("City:");
cityL.setTextColor(Color.BLACK);
cityTR.addView(cityL);
//city textbox
EditText cityTB = new EditText(this);
cityTB.setWidth(250);
cityTR.addView(cityTB);
tl.addView(cityTR);
TableRow countyTR = new TableRow(this);
//county label
TextView countyL = new TextView(this);
countyL.setText("County:");
countyL.setTextColor(Color.BLACK);
countyTR.addView(countyL);
//county textbox
EditText countyTB = new EditText(this);
countyTB.setWidth(250);
countyTR.addView(countyTB);
tl.addView(countyTR);
//Add table layout to the scroll view
//country dropdown
TextView catTitle = new TextView(this);
catTitle.setText("\nPlease select the categories which affect you:\n");
catTitle.setTextColor(Color.BLACK);
tl.addView(catTitle);
//categories
//categories title
String[] cols = {"_id", "cat_name"}; //columns to be searched
Cursor cursor = rdb.query("aa_category", cols, null, null, null, null, null); // save the query to the db
while (cursor.moveToNext()) {
CheckBox catCB = new CheckBox(this);
String name = cursor.getString(1);
int id = cursor.getInt(0);
catCB.setId(id);
catCB.setText("\n"+name+"\n");
catCB.setTextColor(Color.BLACK);
tl.addView(catCB);
}
//add field for new category with a text field that will become active on clicking the checkbox
Button submitButton = new Button(this);
submitButton.setId(99);
submitButton.setText("Submit");
View submitButtonListener = findViewById(99);
submitButtonListener.setOnClickListener(this);
tl.addView(submitButton);
//Add table layout to the scroll view
sv.addView(tl);
//Add scroll view to the main layout
layoutMain.addView(sv);
this.setContentView(layoutMain);
}
}
Your activity isn't implementing View.OnClickListener. Change your class definition to
public class RegisterScreen extends Activity implements View.OnClickListener
and add
public void onClick(View v) {
}
to your Activity class.
RegisterScreen should implement the View.OnClickListener interface i.e.
public class RegisterScreen extends Activity implements View.OnClickListener
and then provide an implementation for the onClick method.

Categories

Resources