In list view the position of particular row can easily be determined through array adapter and then by using onlistitemclick method we can have that value in toast message
but how can we get position or id of any particular text view(when it is clicked) from table view where table rows are generating dynamically through xml parser..
where column names are id, name and class.
id is auto incremented..
pls suggest.
the code is
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
URL sourceUrl = new URL("http://ip-address/test/player.xml");
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
DataList dataList = XMLHandler.DataList;
name = new TextView[dataList.getName().size()];
class = new TextView[dataList.getName().size()];
/** Set the result text in textview and add it to layout */
for (int i = 0; i < DataList.getName().size(); i++) {
TableRow tr = new TableRow(this);
tr.setId(100+i);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to house the name of the province
name[i]= new TextView(this);
name[i].setId(200+i);
name[i].setText(dataList.getName().get(i));
name[i].setTextColor(Color.WHITE);
name[i].setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(name[i]);
class[i] = new TextView(this);
class[i].setId(i);
class[i].setText(dataList.getClass().get(i));
class[i].setTextColor(Color.WHITE);
class[i].setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(class[i]);
t1.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
Invoke ViewGroup method:
public int indexOfChild (View child)
on TableLayout, where child is TableRow. TableRow should be accesible through
public final ViewParent getParent ()
of View inside TableRow.
TableRow tableRow = (TableRow)mTextView.getParent();
int index = -1;
if(parent != null){
index = mTable.indexOfChild(tableRow);
}
if(index < 0){
throw new IllegalStateException("TextView not found");
}
Hope that help, but I haven't tested it.
Related
This is a logic based problem where I will need a small sample of code or an idea supplied for an answer.
I am creating a U.I. programmatically from a JSON response. This app will load in an unknown amount of questions and answers. I'm using loops and conditional statements to create the Views for the U.I. and I am using an AsyncTask for most of the heavy lifting.
Well the problem I can't seem to figure out is: How will I give an unknown amount of views unique id's so that I can use them.
I am providing all the fragment code so you know exactly whats going on:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_assessment, container, false);
ab = getActivity().getActionBar();
infoList = new ArrayList<HashMap<String, String>>();
new Load().execute();
return view;
}
class Load extends AsyncTask<String, Void, String> {
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
JSONArray questions = null;
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading questions. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
// getting JSON string from URL
String componentName = (String) ab.getSelectedTab().getText();
companyName = model.getcName();
projectName = model.getpName();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("company", companyName));
nameValuePairs.add(new BasicNameValuePair("project", projectName));
nameValuePairs.add(new BasicNameValuePair("component",
componentName));
JSONObject json = jParser.makeHttpRequest(url, "POST",
nameValuePairs);
// Check your log cat for JSON response
Log.d("All Questions: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.v("RESPONSE", "Success!");
// products found: getting Array of Questions
questions = json.getJSONArray(TAG_QUESTIONS);
// looping through All Questions
for (int i = 0; i < questions.length(); i++) {
JSONObject c = questions.getJSONObject(i);
// Storing each JSON item in variable
String name = c.getString(TAG_NAME);
String field = c.getString(TAG_FIELD);
String value = c.getString(TAG_VALUE);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_NAME, name);
map.put(TAG_FIELD, field);
map.put(TAG_VALUE, value);
infoList.add(map);
}
} else {
// no products found
Log.v("ERROR", "No JSON for you!");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String string) {
// dismiss the dialog
pDialog.dismiss();
for (int i = 0; i < infoList.size(); i++) {
// get HashMap
HashMap<String, String> map = infoList.get(i);
// if the answer should be a radio button, inflate it
if (map.get(TAG_FIELD).equals(r)) {
Log.v("RESPONSE", "About to create a radio button");
// find
LinearLayout content = (LinearLayout) view
.findViewById(R.id.add);
// create
ArrayList<String> value = new ArrayList<String>();
TextView tv = new TextView(getActivity());
RadioGroup rg = new RadioGroup(getActivity());
rg.setOrientation(RadioGroup.HORIZONTAL);
RadioButton rb = new RadioButton(getActivity());
RadioButton rb2 = new RadioButton(getActivity());
LinearLayout ll = new LinearLayout(getActivity());
// set
rb.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
rb2.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
ll.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
String s = map.get(TAG_VALUE);
for (String parts : s.split("\r\n")) {
value.add(parts);
}
rb.setText(value.get(0));
rb2.setText(value.get(1));
tv.setText(map.get(TAG_NAME));
ll.setOrientation(LinearLayout.HORIZONTAL);
// add
rg.addView(rb);
rg.addView(rb2);
ll.addView(tv);
ll.addView(rg);
content.addView(ll);
}
// create an EditText field
else if (map.get(TAG_FIELD).equals(et)) {
Log.v("RESPONSE", "About to create an EditText");
// find
LinearLayout content = (LinearLayout) getActivity()
.findViewById(R.id.add);
// create
TextView tv = new TextView(getActivity());
EditText et = new EditText(getActivity());
LinearLayout ll1 = new LinearLayout(getActivity());
// set
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT));
et.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
ll1.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
tv.setText(map.get(TAG_NAME));
ll1.setOrientation(LinearLayout.HORIZONTAL);
// add
ll1.addView(tv);
ll1.addView(et);
content.addView(ll1);
}
// create CheckBox
else if (map.get(TAG_FIELD).equals(cb)) {
Log.v("RESPONSE", "About to create a CheckBox");
// find
LinearLayout content = (LinearLayout) getActivity()
.findViewById(R.id.add);
// create
TextView tv = new TextView(getActivity());
CheckBox cb = new CheckBox(getActivity());
LinearLayout ll2 = new LinearLayout(getActivity());
// set
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT));
cb.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT));
ll2.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
tv.setText(map.get(TAG_NAME));
ll2.setOrientation(LinearLayout.HORIZONTAL);
// add
ll2.addView(tv);
ll2.addView(cb);
content.addView(ll2);
}
// Create Spinner
else if (map.get(TAG_FIELD).equals(dm)) {
Log.v("RESPONSE", "About to create a Drop Down Menu");
// find
LinearLayout content = (LinearLayout) getActivity()
.findViewById(R.id.add);
// create
TextView tv = new TextView(getActivity());
LinearLayout ll3 = new LinearLayout(getActivity());
ArrayList<String> spinnerArray = new ArrayList<String>();
ArrayAdapter<String> aa = new ArrayAdapter<String>(
getActivity(),
android.R.layout.simple_spinner_dropdown_item,
spinnerArray);
Spinner spinner = new Spinner(getActivity());
// set
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
spinner.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ll3.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
tv.setText(map.get(TAG_NAME));
String s = map.get(TAG_VALUE);
for (String parts : s.split("\r\n")) {
spinnerArray.add(parts);
System.out.println(parts);
}
spinner.setAdapter(aa);
ll3.setOrientation(LinearLayout.HORIZONTAL);
// add
ll3.addView(tv);
ll3.addView(spinner);
content.addView(ll3);
} else if (map.get(TAG_FIELD).equals(fu)) {
Log.v("RESPONSE", "About to create an ImageView");
// find
LinearLayout content = (LinearLayout) getActivity()
.findViewById(R.id.add);
// create
TextView tv = new TextView(getActivity());
LinearLayout ll4 = new LinearLayout(getActivity());
ImageButton ib = new ImageButton(getActivity());
int ibd = 0;
ibd = R.drawable.ic_menu_camera;
// set
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ll4.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ib.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
tv.setText(map.get(TAG_NAME));
ib.setImageResource(ibd);
ll4.setOrientation(LinearLayout.HORIZONTAL);
//add
ll4.addView(tv);
ll4.addView(ib);
content.addView(ll4);
}
}
}
};
I probably went about this the wrong way to begin with, however this is where I'm at. I will need to give the EditText an id to grab user input, I will need to give the ImageButton and id so it can perform events with the onClick function, and so on and so forth. You get the point I'm sure. So how would one of you tackle this problem?
It's really hard to answer this question. It really depends on what you want to do with the captured data. In any case, you don't have to generated IDs for the elements, you can set new event listeners using Anonymous classes. Then, each of these listeners can save your data to somewhere depending on your key (name?).
I have following XML data,
<RESPONSE>
<param name="Type">NBFundTransfer</param>
<param name="Id">3213</param>
<param name="Token">26&ffr$5%877</param>
<param name="Stage">1</param>
</RESPONSE>
I want to fetch the node by its name.I use following method to fetch data,
NodeList nl = doc.getElementsByTagName("RESPONSE");
String[] Agreement = new String[nl.getLength()];
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if (item.getNodeType() == Node.ELEMENT_NODE) {
Element ielem = (Element) item;
NodeList id = ielem.getElementsByTagName("param");
Data[i] = id.item(0).getChildNodes().item(0).getNodeValue();
}
}
But the problem is, Iam only getting the data "NBFundTransfer" from first node which is names as "Type" .I want to fetch the data from all other nodes(Id,Token etc).Please someone help me to get a solution.Thank you..
public class XMLParsingExample extends Activity {
/** Create Object For SiteList Class */
SitesList sitesList = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** Create a new layout to display the view */
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);
/** Create a new textview array to display the results */
TextView name[];
TextView website[];
TextView category[];
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/** Get result from MyXMLHandler SitlesList Object */
sitesList = MyXMLHandler.sitesList;
/** Assign textview array lenght by arraylist size */
name = new TextView[sitesList.getName().size()];
website = new TextView[sitesList.getName().size()];
category = new TextView[sitesList.getName().size()];
/** Set the result text in textview and add it to layout */
for (int i = 0; i < sitesList.getName().size(); i++) {
name[i] = new TextView(this);
name[i].setText("Name = "+sitesList.getName().get(i));
website[i] = new TextView(this);
website[i].setText("Website = "+sitesList.getWebsite().get(i));
category[i] = new TextView(this);
category[i].setText("Website Category = "+sitesList.getCategory().get(i));
layout.addView(name[i]);
layout.addView(website[i]);
layout.addView(category[i]);
}
/** Set the layout view to display */
setContentView(layout);
}
}
In my app the user chooses how many seekbars they need and then my code generates them (see below).
// dynamically creates the view objects
tL = (TableLayout)findViewById(R.id.tableLayout1);
// creates all the fields
for(int i = 1; i <= numOfStockTanks; i++) {
TableRow tR = new TableRow(this);
// creates the textView
tV1 = new TextView(this);
tV1.setText(" " + tankNum[i - 1] + ": ");
tV1.setPadding(2, 0, 0, 0);
// creates the seekBar
sBGauge = new SeekBar(this);
sBGauge.setMax(depthL - 1);
sBGauge.setMinimumWidth(150);
sBGauge.setId(2000 + 1);
sBGauge.setOnSeekBarChangeListener(this);
// shows the progress of the seekBar
tVGauge = new TextView(this);
tVGauge.setText("0-0.0\"");
tVGauge.setId(3000 + i);
// adds objects to row
tR.addView(tV1);
tR.addView(sBGauge);
tR.addView(tVGauge);
// add the TableRow to the TableLayout
tL.addView(tR, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// creates new tableRow
TableRow tR2 = new TableRow(this);
// add's a "+" button to tableRow
buttonPlus = new Button (this);
buttonPlus.setWidth(60);
buttonPlus.setText("+");
buttonPlus.setId(4000 + i);
buttonPlus.setOnClickListener(new MyPOnClickListener());
// add's a "-" button to tableRow
buttonMinus = new Button (this);
buttonMinus.setWidth(60);
buttonMinus.setText("-");
buttonMinus.setId(5000 + i);
buttonMinus.setOnClickListener(new MyMOnClickListener());
// add TextView tVChange to show change from previous sqlite entry
tVChange = new TextView (this);
tVChange.setText("Change");
tVChange.setId(6000 + i);
// add the TextView and the buttons to the new TableRow
tR2.addView(buttonPlus);
tR2.addView(buttonMinus);
tR2.addView(tVChange);
// add the TableRow to the TableLayout
tL.addView(tR2,new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
} // end for statement
my problem is when I use my onProgressChanged method:
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
int seekId = sBGauge.getId();
seekId = seekId - 2000;
try {
tVGauge = (TextView) findViewById(seekId + 3000);
} // end try
catch (Exception e) {Toast.makeText(this, "fail", Toast.LENGTH_LONG).show();}
try {
// sets the text of the textview
tVGauge.setText(depth.get(progress));
} // end try
catch (Exception e) {}
manualP = progress;
}
My problem is that all my seekBars only change the first progress bars textView, the buttons change the proper text view.
Thanks for your help
You are setting the same id to each seekbar
sBGauge.setId(2000 + 1);
change 1 to i
sBGauge.setId(2000 + i);
I am able to create a dialog box and show a table in it, but i wanted to add some more rows to it dynamically.
These rows should have textviews in it (say 3 in a row).
Please direct me on this.
Thanks in advance
My code, which is not working, is as follows:
struct3x5 is layout file with table layout and table of 3x5 dimension
1). On click event code
button.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0) {
final String NAMESPACE = "http://tempuri.org/";
final String METHOD_NAME = "method";
final String SOAP_ACTION = "http://tempuri.org/method";
final String URL = "http://xyz/pqr/webserv.asmx";
// custom dialog
final Dialog dialog = new Dialog(context,R.style.cust_dialog);
dialog.setContentView(R.layout.struct3x5);
dialog.setTitle("XYZ");
// set the custom dialog components - text, image and button
TextView text1 = (TextView) dialog.findViewById(R.id.textView1);
text1.setText("");
TextView text2 = (TextView) dialog.findViewById(R.id.textView2);
text2.setText("Vehicle(Rs in Lacs)");
TextView text3 = (TextView) dialog.findViewById(R.id.textView3);
text3.setText("TPP(Rs in Lacs)");
TextView text4 = (TextView) dialog.findViewById(R.id.textView4);
text4.setText("PL(Rs in Lacs)");
TextView text5 = (TextView) dialog.findViewById(R.id.textView5);
text5.setText("Insurance(Rs in Lacs)");
String [] data = {};
String x = " ";
int colsize = 5;
int rowcount =(data.length)/colsize;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
data = getarray(response);
}
catch (Exception e){
Toast.makeText(classname.this,"error",Toast.LENGTH_LONG).show();
}
createtable(data,rowcount);
dialog.show();
}
});
2). _Function to create table
private void createtable(String[] data, int rowcount) {
// TODO Auto-generated method stub
LinearLayout t1=(LinearLayout)findViewById(R.id.tableLayout3x5);
//TextView[] tva= new TextView[data.length];
int count =0;
for(int i=0;i<rowcount;i++)
{
TableRow tr=new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
for(int j=0;j<(data.length/rowcount); j++)
{
TextView text = new TextView(this);
text.setText(data[count].toString());
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
tr.addView(text);
count++;
}
t1.addView(tr, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
}
You can do something along these lines to dynamically add more rows:
LinearLayout table = (LinearLayout)findViewById(R.id.my_container);
TableRow text_row = new TableRow(this);
text_row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// create new text row for label
TextView text = new TextView(this);
text.setText("My Text");
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
text_row.addView(text);
table.addView(text_row, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
I have a TableRow that is loaded dynamically. It contains multiple EditTexts and CheckBoxes. How do I get the user input from these EditTexts and CheckBoxes?
This my Code
public void cargarProductos(SQLiteDatabase db){
TableLayout tabla = (TableLayout) findViewById(R.id.Detalle);
Cursor cProd = db.rawQuery("SELECT * FROM vstEncProductos WHERE IdCliente="+idCliente+" AND Idcategoria="+IdCategoria, null);
int ValorChk = 0;
if (cProd.moveToFirst()) {
do {
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
row.setId(cProd.getInt(0));
ImageButton btnBarCode = new ImageButton(this);
btnBarCode.setBackgroundResource(R.drawable.barcodereader48);
btnBarCode.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
startActivityForResult(intent, 0);
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
showDialog(R.string.result_succeeded, "Format: " + format + "\nContents: " + contents);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
});
row.addView(btnBarCode, new TableRow.LayoutParams(0));
TextView txtProducto = new TextView(this);
txtProducto.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
txtProducto.setText(cProd.getString(1));
txtProducto.setWidth(230);
row.addView(txtProducto, new TableRow.LayoutParams(1));
EditText txtPrecio = new EditText(this);
txtPrecio.setWidth(130);
txtPrecio.setInputType(InputType.TYPE_CLASS_NUMBER);
row.addView(txtPrecio, new TableRow.LayoutParams(2));
TextView txtPrecioAnt = new TextView(this);
txtPrecioAnt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
txtPrecioAnt.setText(cProd.getString(7));
txtPrecioAnt.setWidth(115);
txtPrecioAnt.setGravity(Gravity.RIGHT);
row.addView(txtPrecioAnt, new TableRow.LayoutParams(3));
CheckBox chkPresencia = new CheckBox(this);
ValorChk=cProd.getInt(4);
chkPresencia.setChecked(ValorChk==-1);
chkPresencia.setWidth(50);
row.addView(chkPresencia, new TableRow.LayoutParams(4));
CheckBox chkPrecioPromo = new CheckBox(this);
ValorChk=cProd.getInt(4);
chkPrecioPromo.setChecked(ValorChk==-1);
chkPrecioPromo.setWidth(50);
row.addView(chkPrecioPromo, new TableRow.LayoutParams(4));
CheckBox chkAlerta = new CheckBox(this);
ValorChk=cProd.getInt(4);
chkAlerta.setChecked(ValorChk==-1);
chkAlerta.setWidth(50);
row.addView(chkAlerta, new TableRow.LayoutParams(4));
tabla.addView(row, new TableLayout.LayoutParams());
} while (cProd.moveToNext());
}
cProd.close();
I'm assuming you're using some sort of adapter class to load the data into your table. When you create a view, simply assign an OnClickListener to the checkboxes and a TextWatcher to the EditTexts. Use the callbacks from these classes to do what ever it is you want with the users input. Am I understanding your question correctly?
when you are creating new tablerows you can save each file in a multi vector of, for example, strings. Then you only must get size of each vector inside theparent vector. My example with your cody modified:
Vector<Vector<String>> result = new Vector<Vector<String>>();
Vector<String> vecAux = new Vector<String>();
TextView txtProducto = new TextView(this);
txtProducto.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
txtProducto.setText(cProd.getString(1));
txtProducto.setWidth(230);
row.addView(txtProducto, new TableRow.LayoutParams(1));
vecAux.add(cProd.getString(1));
EditText txtPrecio = new EditText(this);
txtPrecio.setWidth(130);
txtPrecio.setInputType(InputType.TYPE_CLASS_NUMBER);
row.addView(txtPrecio, new TableRow.LayoutParams(2));
TextView txtPrecioAnt = new TextView(this);
txtPrecioAnt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
txtPrecioAnt.setText(cProd.getString(7));
txtPrecioAnt.setWidth(115);
txtPrecioAnt.setGravity(Gravity.RIGHT);
row.addView(txtPrecioAnt, new TableRow.LayoutParams(3));
vecAux.add(cProd.getString(7));
CheckBox chkPresencia = new CheckBox(this);
ValorChk=cProd.getInt(4);
chkPresencia.setChecked(ValorChk==-1);
chkPresencia.setWidth(50);
row.addView(chkPresencia, new TableRow.LayoutParams(4));
CheckBox chkPrecioPromo = new CheckBox(this);
ValorChk=cProd.getInt(4);
chkPrecioPromo.setChecked(ValorChk==-1);
chkPrecioPromo.setWidth(50);
row.addView(chkPrecioPromo, new TableRow.LayoutParams(4));
CheckBox chkAlerta = new CheckBox(this);
ValorChk=cProd.getInt(4);
chkAlerta.setChecked(ValorChk==-1);
chkAlerta.setWidth(50);
row.addView(chkAlerta, new TableRow.LayoutParams(4));
tabla.addView(row, new TableLayout.LayoutParams());
result.add(vecAux);
And get results looking for all position of the vector:
String texto = "";
for (int i = 0; i < result.size(); i++) {
for (int j = 0; j < result.elementAt(i).size(); j++) {
texto += result.elementAt(i).elementAt(j) + "\t";
}
}
For get if checkbox is checked or not you can get it by ID (findViewById).
I hope help you, bye bye ;-)