I’m getting data from mssql dynamically in my table. I want to get values in selected row as String. For example i want to get “99” , “Yonca” , “Lodi” values for this screen. How can i do this? Here is my creating table code :
public void addData()
{
for(int i = 0 ; i < protokolNo.length ; i++)
{
/**
* Creating table row here
*/
tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
tVProtokolNo = new TextView (this);
tVProtokolNo.setText(protokolNo[i]);
tVProtokolNo.setTextColor(Color.RED);
tVProtokolNo.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tVProtokolNo.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
tVProtokolNo.setPadding(5, 5, 5, 5);
tr.addView(tVProtokolNo);
TextView tVAdi = new TextView(this);
tVAdi.setText(adi[i]);
tVAdi.setTextColor(Color.RED);
tVAdi.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tVAdi.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
tVAdi.setPadding(5, 5, 5, 5);
tr.addView(tVAdi);
TextView tVSoyadi = new TextView(this);
tVSoyadi.setText(soyadi[i]);
tVSoyadi.setTextColor(Color.RED);
tVSoyadi.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tVSoyadi.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
tVSoyadi.setPadding(5, 5, 5, 5);
tr.addView(tVSoyadi);
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
/**
* Colouring selected row
*/
tr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setBackgroundColor(Color.DKGRAY);
v.showContextMenu();
}
});
registerForContextMenu(tr);
}
}
This is dirty but working.
Create a global private variable in your Activity class
called
TableRow tr1=null;then you can use the following code within your
addData()methodbefore
registerForContextMenu(tr);call:Then use the following in the same Activity to make it work with the context menus as far as I got it from your code:
so basically tr1 variable will host your selected TableRow.
But do as everyone says use the ListView for the tasks like this one and just use RelativeLayouts for the rows or anything.
hope it clarifies it abit.