Android how to hide the table lyout - java

In my android application a love compatibility test is doing.. where first the details of boys and then details of girls are entered in the same page..one after another. and separate save button for saving boy details and girl details and these data is saved in separate databases. and there is a recall button also there for both boys and girls. When this recall button is pressed the database will opened and from that user can select the name to be checked. When he press the corresponding data has to be entered into the corresponding edittexts. In my case I don't know how to close this tablerow. that mean the database opened.then only the data will go to the corresponding edittext box.
I am giving my code below
MainActivity
btn4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor c = dbb.rawQuery("SELECT * from Data3", null);
int count = c.getCount();
c.moveToFirst();
TableLayout tableLayout = new TableLayout(getApplicationContext());
tableLayout.setVerticalScrollBarEnabled(true);
TableRow tableRow;
TextView textView1, textView2,textView3, textView4, textView5, textView6, textView7, textView8 ;
tableRow = new TableRow(getApplicationContext());
textView1 = new TextView(getApplicationContext());
textView1.setText("First Name");
textView1.setTextColor(Color.BLACK);
textView1.setTypeface(null, Typeface.BOLD);
textView1.setPadding(20, 20, 20, 20);
tableRow.addView(textView1);
textView2 = new TextView(getApplicationContext());
textView2.setText("Last Name");
textView2.setTextColor(Color.RED);
textView2.setTypeface(null, Typeface.BOLD);
textView2.setPadding(10, 10, 10, 10);
tableRow.addView(textView2);
tableLayout.addView(tableRow);
for(Integer j=0; j<count; j++)
{
tableRow = new TableRow(getApplicationContext());
textView3= new TextView(getApplicationContext());
textView3.setText(c.getString(c.getColumnIndex("ffirstname")));
textView3.setClickable(true);
ett1=textView3.getText().toString();
textView4 = new TextView(getApplicationContext());
textView4.setText(c.getString(c.getColumnIndex("fmiddlename")));
textView4.setClickable(true);
ett2=textView4.getText().toString();
textView5 = new TextView(getApplicationContext());
textView5.setText(c.getString(c.getColumnIndex("flastname")));
textView5.setClickable(true);
ett3=textView5.getText().toString();
textView6 = new TextView(getApplicationContext());
textView6.setText(c.getString(c.getColumnIndex("fdayofbirth")));
textView6.setClickable(true);
ett4=textView6.getText().toString();
textView7 = new TextView(getApplicationContext());
textView7.setText(c.getString(c.getColumnIndex("fmonthofbirth")));
textView7.setClickable(true);
ett5=textView7.getText().toString();
textView8 = new TextView(getApplicationContext());
textView8.setText(c.getString(c.getColumnIndex("fyearofbirth")));
textView8.setClickable(true);
ett6=textView8.getText().toString();
textView3.setPadding(10, 10, 10,10);
textView5.setPadding(10, 10, 10, 10);
tableRow.addView(textView3);
tableRow.addView(textView5);
tableLayout.addView(tableRow);
c.moveToNext();
final List<String> list = new ArrayList<String>();
list.add(textView3.getText().toString());
list.add(textView4.getText().toString());
list.add(textView5.getText().toString());
list.add(textView6.getText().toString());
list.add(textView7.getText().toString());
list.add(textView8.getText().toString());
textView3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
c.close();
setContentView(tableLayout);
dbb.close();
}
});

Declare the table layout out side button click and to make it GONE/INVISIBLE do Like this
tablelayout.setVisibility(View.INVISIBLE);//white space will be available
Or
tablelayout.setVisibility(View.GONE);//No white space

Related

TableRow is returning empty value in TableLayout?

I have an Activity which does not have any layout file. Here there is a TableLayout which has 5 input rows. I want to get those edittext value from the rows. I have tried a lot but still unable to get the data from the rows.
Here is my activity.java file.Is there any other way to get the data from edittext? I have tried this.Duplicate Question but my app crashes with showing the error "TableRow can not be cast into EditText".
public class MainActivity extends AppCompatActivity {
ScrollView sv;
TableLayout myTableLayout;
String userName,
firstName,
city,
zipCode,
age;
UserListAdapter adapter;
RecyclerView recyclerView;
List <User> userList;
TableRow inputRow;
String temp = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("TurnToTech", "Project Name - Dynamic table view");
sv = new ScrollView(this);
userList = new ArrayList <>();
myTableLayout = new TableLayout(this);
drawScreen();
recyclerView = new RecyclerView(this);
}
public void drawScreen() {
// this might be a redraw, so we clean the view's container
myTableLayout.removeAllViews();
sv.removeAllViews();
// special rows
TableRow buttonRow = new TableRow(this);
TableRow titleRow = new TableRow(this);
//Alerts
final AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Saveing");
alertDialog.setMessage("Saved..");
final AlertDialog alertDialog1;
alertDialog1 = new AlertDialog.Builder(this).create();
alertDialog1.setTitle("Cancel");
alertDialog1.setMessage("Rejected");
// margins
buttonRow.setPadding(20, 10, 20, 10);
titleRow.setPadding(20, 10, 20, 10);
// the title
TextView title = new TextView(this);
title.setText("Data input form");
title.setTextSize(14);
title.setTextColor(Color.BLACK);
title.setGravity(Gravity.CENTER_HORIZONTAL);
titleRow.addView(title);
titleRow.setGravity(Gravity.CENTER);
// the title tablelayout
TableLayout titleTableLayout = new TableLayout(this);
titleTableLayout.addView(titleRow);
// we add the title layout to the main one
myTableLayout.addView(titleTableLayout);
/// the 5 input rows
inputRow(myTableLayout, "Name", 30, 10000); //returning ""
inputRow(myTableLayout, "First Name", 30, 10001); //returning ""
inputRow(myTableLayout, "Age", 3, 10002); //returning ""
inputRow(myTableLayout, "City", 20, 10003); //returning ""
inputRow(myTableLayout, "Zip Code", 6, 10004); //returning ""
// the buttons table layout
// purpose : right align for both buttons
TableLayout buttonsLayout = new TableLayout(this);
buttonRow.setPadding(20, 50, 40, 0);
// the accept and cancel buttons
Button btAccept = new Button(this);
btAccept.setText("Save");
btAccept.setOnClickListener(new View.OnClickListener() {#Override
public void onClick(View v) {
//TODO here I want to get all the row value that I filled from the table and store the value inside the user object.
User user = new User(userName, firstName, age, city, zipCode);
userList.add(user);
adapter = new UserListAdapter(userList, MainActivity.this);
recyclerView.setAdapter(adapter);
}
});
Button btCancel = new Button(this);
btCancel.setText("Cancel");
btCancel.setOnClickListener(new View.OnClickListener() {#Override
public void onClick(View v) {
alertDialog1.show();
}
});
buttonRow.addView(btAccept);
buttonRow.addView(btCancel);
buttonRow.setGravity(Gravity.RIGHT);
buttonsLayout.addView(buttonRow);
myTableLayout.addView(buttonsLayout);
sv.addView(myTableLayout);
setContentView(sv);
}
public void inputRow(TableLayout tl, String label, int inputSize, int inputID) {
inputRow = new TableRow(this);
TextView tv = new TextView(this);
EditText edit = new EditText(this);
// some margin
inputRow.setPadding(20, 10, 20, 0);
tv.setText(label);
edit.setMaxWidth(inputSize * 7);
edit.setMinimumWidth(inputSize * 7);
edit.setId(inputID);
edit.setGravity(Gravity.RIGHT);
inputRow.addView(tv);
inputRow.addView(edit);
tl.addView(inputRow);
}
}
I mentioned a todo inside the onClick event.
Inside of onClick() for btAccept, you'll need to call something like this for each EditText:
#SuppressLint("ResourceType") EditText nameEditText = findViewById(10000);
String nameEntered = nameEditText.getText().toString();
.
.
.
One you've done this for all your EditTexts, you can store them in a User object.

dynamically add rows to a table with java code

I hope someone can help me here...
I want to add rows to a table dynamically with a for Loop. This is just for example. But when I test it, the Screen where the table should be showed is empty. I don't know where the Problem is, it just Shows nothing.
Here is my Code:
private void setElementsList() {
TableLayout tableLayout = findViewById(R.id.tablelayout);
for (int i=0; i<5; i++) {
// Creation row
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, 70));
tableRow.setPadding(0,0,0,8);
LinearLayout Newrowlayout =new LinearLayout(this);
Newrowlayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,5));
Newrowlayout.setOrientation(LinearLayout.HORIZONTAL);
Newrowlayout.setBackgroundColor(16746559);
// Creation textView
TextView text2 = new TextView(this);
text2.setText("Order ID: ");
text2.setTextSize(21);
text2.setTextColor(16508374);
text2.setGravity(Gravity.CENTER);
text2.setPadding(0,0,2,0);
text2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
// Creation textView
TextView text = new TextView(this);
text.setText(Integer.toString(i));
text.setTextSize(21);
text.setTextColor(16508374);
text.setGravity(Gravity.CENTER);
text.setPadding(2,0,10,0);
text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
// Creation textView
TextView text3 = new TextView(this);
text3.setGravity(Gravity.CENTER);
text3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT, 3));
// Creation button
Button button = new Button(this);
button.setText(">");
button.setTextSize(30);
button.setTextColor(16508374);
button.setBackgroundColor(16746559);
button.setLayoutParams(new TableRow.LayoutParams(70,70));
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
// Creation textView
TextView text4 = new TextView(this);
text4.setGravity(Gravity.CENTER);
text4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT, 3));
// Creation textView
TextView text5 = new TextView(this);
text5.setGravity(Gravity.CENTER);
text5.setBackgroundColor(16741149);
text5.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT, 1));
Newrowlayout.addView(text2);
Newrowlayout.addView(text);
tableRow.addView(Newrowlayout);
tableRow.addView(text3);
tableRow.addView(button);
tableRow.addView(text4);
tableRow.addView(text5);
tableLayout.addView(tableRow);
}
}
If you Need further Details plz ask.
Best regards
domidoof

How to assign different values to two different table without writing almost same code for other table?

I want to create two tables which have different headers in first row. both tables have 4 columns in header row. How can i create two table with different header values without writing this same code twice?
public void addHeaders(TableLayout t) {
/* Create a TableRow dynamically */
TableRow tr = new TableRow(this);
tr.setBackgroundColor(GRAY);
tr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
/* Creating a TextView to add to the row */
TextView addressTV = new TextView(this);
addressTV.setText("Address");
addressTV.setTextColor(Color.BLACK);
addressTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
addressTV.setGravity(Gravity.CENTER_HORIZONTAL);
addressTV.setPadding(0, 7, 0, 7);
addressTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.7f));
tr.addView(addressTV); // Adding textView to tablerow.
/* Creating a TextView to add to the row */
TextView typeTV = new TextView(this);
typeTV.setText("Type");
typeTV.setTextColor(Color.BLACK);
typeTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
typeTV.setGravity(Gravity.CENTER_HORIZONTAL);
typeTV.setPadding(0, 7, 0, 7);
typeTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
tr.addView(typeTV); // Adding textView to tablerow.
/* Creating another textview */
TextView amountTV = new TextView(this);
amountTV.setText("Amount");
amountTV.setTextColor(Color.BLACK);
amountTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
amountTV.setGravity(Gravity.CENTER_HORIZONTAL);
amountTV.setPadding(0, 7, 0, 7);
amountTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.2f));
tr.addView(amountTV); // Adding textView to tablerow.
/* Creating another textview */
TextView dateTV = new TextView(this);
dateTV.setText("Date");
dateTV.setTextColor(Color.BLACK);
dateTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
dateTV.setGravity(Gravity.CENTER_HORIZONTAL);
dateTV.setPadding(0, 7, 0, 7);
dateTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.5f));
tr.addView(dateTV); // Adding textView to tablerow.
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
}
Try passing the header names as an input. Then you can reuse the code to create your table objects while dynamically adjusting the header text fields.
e.g. Here is simple example, assuming always 4 columns...
public void callingFunction() {
TableLayout tl1 = // something;
TableLayout tl2 = // something else;
addHeaders(tl1, "Address", "Type", "Amount", "Date");
addHeaders(tl2, "new", "strings", "for", "table");
}
public TableRow addHeaders(TableLayout tl, String ... names) {
if (names.length != 4) throw new Exception("Unexpected number of table header names");
/* Create a TableRow dynamically */
TableRow tr = new TableRow(this);
tr.setBackgroundColor(GRAY);
tr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
/* Creating a TextView to add to the row */
TextView addressTV = new TextView(this);
addressTV.setText(names[0]);
addressTV.setTextColor(Color.BLACK);
addressTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
addressTV.setGravity(Gravity.CENTER_HORIZONTAL);
addressTV.setPadding(0, 7, 0, 7);
addressTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.7f));
tr.addView(addressTV); // Adding textView to tablerow.
/* Creating a TextView to add to the row */
TextView typeTV = new TextView(this);
typeTV.setText(names[1]);
typeTV.setTextColor(Color.BLACK);
typeTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
typeTV.setGravity(Gravity.CENTER_HORIZONTAL);
typeTV.setPadding(0, 7, 0, 7);
typeTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
tr.addView(typeTV); // Adding textView to tablerow.
/* Creating another textview */
TextView amountTV = new TextView(this);
amountTV.setText(names[2]);
amountTV.setTextColor(Color.BLACK);
amountTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
amountTV.setGravity(Gravity.CENTER_HORIZONTAL);
amountTV.setPadding(0, 7, 0, 7);
amountTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.2f));
tr.addView(amountTV); // Adding textView to tablerow.
/* Creating another textview */
TextView dateTV = new TextView(this);
dateTV.setText(names[3]);
dateTV.setTextColor(Color.BLACK);
dateTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
dateTV.setGravity(Gravity.CENTER_HORIZONTAL);
dateTV.setPadding(0, 7, 0, 7);
dateTV.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.5f));
tr.addView(dateTV); // Adding textView to tablerow.
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
}

Android How to change data of Textview by clicking on button

First of all, the app looks like this.
How to make - if I click on Add, on its column the textview is updated with value + 1?
I'm creating TextView and Button in a Loop;
for(int i = 0;i < playercountint; i++)
{
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,(100/playercountint)));
layout.setGravity(Gravity.CENTER_HORIZONTAL);
TextView tt = new TextView(this);
tt.setText("0");
tt.setTextSize(14);
tt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tt.setGravity(Gravity.CENTER_HORIZONTAL);
Button btadd = new Button(this);
btadd.setText("Add");
btadd.setId(2);
btadd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
????? what here?
}
});
}
What should be written in onClick function , so only TextView value which is in buttons column is changed.
There is one outer LinearLayout which is horizontally oriented, and those which are created within a loop is vertical Linear Layouts.
Maybe i should create a template for 1 loop iteration?
First make your textview final and them set it's value in onClick
for(int i = 0;i < playercountint; i++)
{
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,(100/playercountint)));
layout.setGravity(Gravity.CENTER_HORIZONTAL);
final TextView tt = new TextView(this);
tt.setText("0");
tt.setTextSize(14);
tt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tt.setGravity(Gravity.CENTER_HORIZONTAL);
Button btadd = new Button(this);
btadd.setText("Add");
btadd.setId(2);
btadd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
tt.setText(String.valueOf(Integer.parseInt(tt.getText())+1));
}
});
}
You can write one function that returns linearlayout:
public View getPlayerView(){
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,(100/playercountint)));
layout.setGravity(Gravity.CENTER_HORIZONTAL);
final TextView tt = new TextView(this);
tt.setText("0");
tt.setTextSize(14);
tt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tt.setGravity(Gravity.CENTER_HORIZONTAL);
Button btadd = new Button(this);
btadd.setText("Add");
btadd.setId(2);
btadd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
tt.setText(String.valueOf(Integer.parseInt(tt.getText())+1));
}
});
layout.add(tt);
layout.add(btadd);
return layout;
}
Call this function in a loop.
tt.setText("something");
tt.invalidate();
my bad I didn't even notice it was a for loop uh you need to hold a reference to the text view.. make your textview final
tt.setText(Integer.parse(tt.getText().toString()) + 1);
But, I strongly recommend you design UI (layout) in the *.xml file!
See more: http://developer.android.com/guide/topics/ui/declaring-layout.html
You should provide your TextView with an unique id (.setId(...)). Having this, in your onClick method simply use something like this:
final TextView tv = (TextView) findViewById(R.id.your_textview_id);
final String cur_text = tv.getText();
Integer plus_one = Integer.valueOf(cur_text);
plus_one++;
tv.setText(plus_one.toString());
Didn't try it but should work.
static int counter = 0;
btn_Add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
counter ++;
tv_Display.setText("Your Total is : " + counter);
}
});

How to set onClickListener for the textviews generated dynamically?

Can anyone please guide me on how to setOnClickListener for the TextViews that are generated dynamically.
I have few buttons in my app.Now when a particular button is clicked than some specific text elements are retrieved from the database based on the the number of elements returned corresponding TextViews are generated in order to display the retrieved text elements.
Now the problem that i'm having is that i don't know how to set onClickListner for the dynamically generated TextViews.Following is the piece of code where i'm creating my TextViews.Please guide me on what should i do.thank you
public void onClick(View v) {
switch (v.getId()) {
case R.id.imageButton1:
catagory = "General";
IndependentDB genData = IndependentDB.getInstance();
genData.open(this);
ArrayList<TextHolder> genList = new ArrayList<TextHolder>();
genList = genData.getAllTextFromGenT();
genData.close();
x = genList.size();
String xstr = new StringBuilder().append(x).toString();
System.out.println(xstr);
mainText = new TextView[x];
textLayout = new LinearLayout[x];
llseperator = new LinearLayout[x];
textLayoutContainer
.setBackgroundResource(R.color.dark_navy_blue);
if (!genList.isEmpty()) {
for (int i = 0; i < x; i++) {
TextHolder firstOne = genList.get(i);
String text = firstOne.getText();
mainText[i] = new TextView(this);
mainText[i].setId(i);
mainText[i].setText("Text");
mainText[i].setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mainText[i].setTextSize(25);
mainText[i].setGravity(Gravity.CENTER);
mainText[i].setText(text);
mainText[i].setTextColor(0xFFFFFFFF);
mainText[i].setClickable(true);
mainText[i].setOnClickListener(this);
llseperator[i] = new LinearLayout(this);
llseperator[i].setId(i);
llseperator[i].setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
llseperator[i].setGravity(Gravity.CENTER);
llseperator[i]
.setBackgroundResource(R.drawable.tv_seperator);
textLayout[i] = new LinearLayout(this);
textLayout[i].setId(i);
textLayout[i].setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
textLayout[i].setGravity(Gravity.CENTER);
textLayout[i].addView(mainText[i]);
textLayoutContainer.addView(textLayout[i]);
textLayoutContainer.addView(llseperator[i]);
}// End of for
}// End of If
break;}
You already have onClick() method in Activity class (implemented View.setOnClickListener) so I suggest you to create a new class which implements View.setOnClickListener interface to handle click of TextView.
Try,
class TextClick implements View.setOnClickListener {
#Override
public void onClick(View view) {
TextView tx=(TextView) view;
...
}
}
and set click listener,
TextClick click=new TextClick();
for (int i = 0; i < x; i++) {
TextHolder firstOne = genList.get(i);
String text = firstOne.getText();
mainText[i] = new TextView(this);
mainText[i].setOnClickListener(click);
...
}
It's the same setting on click listeners regardless of if the view was dynamically generated.
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dosomething();
}
});
For example. you have a List tvs to store your TextView Objects created by the db result. What you should do is like this:
for(int i =0;i<tvs.count;i++){
tvs.get(i).setOnClickListener(new OnClickListener(){
...
})
}

Categories

Resources