tablelayout


How to dynamically draw a TableLayout from AsyncTask


My question is as the title states, I dynamically draw a table when I press a button and it works. But due to the fact that I need to show a process dialog while the table is being drawn I have tried using AsyncTask and it keeps crashing in the doInBackground() function.
Can anyone perhaps tell me what I am doing wrong?
private class TransactionsTask extends AsyncTask<Long, Void, Void>
{
final TextView[] tx = new TextView[10];
final TableRow[] tr = new TableRow[10];
final TableLayout tl = (TableLayout)findViewById(R.id.maintable);
final ProgressDialog dialog = ProgressDialog.show(TransactionsActivity.this, "", "Retrieving...", true);
protected void onPreExecute()
{
this.dialog.show();
}
protected Void doInBackground(Long... params)
{
// A request for all transactions on the specified data is made to the S-Qube here
com.example.sqube.SettingsActivity.out.println(c + "0130;EmployeeId=4;LastTXId=0;FirstTXId=0;SYear=11;SMon=" + (mStartMonth + 1) + ";SDay=" + mStartDay + ";EYear=11;EMon=" + (mEndMonth + 1) + ";EDay=" + mEndDay + ";Area=0;View=1;TXType=1;" + d);
com.example.sqube.SettingsActivity.out.flush();
while(control == false)
{
try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
tl.removeAllViews(); // The view is first cleared before drawn again
// This code it used to dynamically draw the transactions table based on the number of transactions received from the S-Qube
tr[0] = new TableRow(TransactionsActivity.this);
tr[1] = new TableRow(TransactionsActivity.this);
tr[2] = new TableRow(TransactionsActivity.this);
tr[3] = new TableRow(TransactionsActivity.this);
tx[0] = new TextView(TransactionsActivity.this);
tx[1] = new TextView(TransactionsActivity.this);
tx[2] = new TextView(TransactionsActivity.this);
tx[3] = new TextView(TransactionsActivity.this);
tx[0].setText("Date ");
tx[0].setTextColor(Color.BLACK);
tx[0].setTypeface(null, 1);
tr[0].addView(tx[0]);
tx[1].setText("Device ");
tx[1].setTextColor(Color.BLACK);
tx[1].setTypeface(null, 1);
tr[0].addView(tx[1]);
tx[2].setText("Access Type ");
tx[2].setTextColor(Color.BLACK);
tx[2].setTypeface(null, 1);
tr[0].addView(tx[2]);
tx[3].setText("Areas ");
tx[3].setTextColor(Color.BLACK);
tx[3].setTypeface(null, 1);
tr[0].addView(tx[3]);
tl.addView(tr[0], new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tl.addView(tr[1], new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tl.addView(tr[2], new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tl.addView(tr[3], new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
for(i = 0; i < com.example.sqube.SettingsActivity.Count1; i++)
{
tr[i] = new TableRow(TransactionsActivity.this);
tx[0] = new TextView(TransactionsActivity.this);
tx[1] = new TextView(TransactionsActivity.this);
tx[2] = new TextView(TransactionsActivity.this);
tx[3] = new TextView(TransactionsActivity.this);
tx[0].setText(Date[i] + " ");
tx[0].setTextColor(Color.BLACK);
tx[0].setTypeface(null, 1);
tx[1].setText(Device[i] + " ");
tx[1].setTextColor(Color.BLACK);
tx[1].setTypeface(null, 1);
tx[2].setText(Access_Type[i] + " ");
tx[2].setTextColor(Color.BLACK);
tx[2].setTypeface(null, 1);
tx[3].setText(Area[i] + " ");
tx[3].setTextColor(Color.BLACK);
tx[3].setTypeface(null, 1);
tr[i].addView(tx[0]);
tr[i].addView(tx[1]);
tr[i].addView(tx[2]);
tr[i].addView(tx[3]);
tl.addView(tr[i], new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
com.example.sqube.SettingsActivity.Count1 = 0;
control = false;
return null;
}
protected void onPostExecute(final Void unused)
{
dialog.dismiss();
}
}

Related Links

AutoLink Doesnot work on Table Layout lolipop
Getting value from dynamic table in Android
set background image in table layout
How to dynamically draw a TableLayout from AsyncTask
Tablelayout and LinearLayout - visible and invisble

Categories

HOME
twitter
osgi
image
date
wso2
gremlin
iot
sqlite-net-extensions
cmd
pivotal-cloud-foundry
constraint-programming
swagger-ui
multiple-records
vifm
floating-action-button
mapserver
msp430
caml
lombok
propel
normalizr
shared-hosting
alpine
ml
jasonette
dcevm
cultureinfo
captiveportal
crystal-reports-2010
cas
fgetcsv
replaceall
primitive
delicious-api
srcset
google-rich-snippets
frame
nameservers
junit5
accelerate-framework
y86
mmenu
plsql-psp
file-format
lto
espeak
uft-api
awt
android-tabhost
ncalc
firebase-admin
thin
btrace
filepicker
jquery-validate
integrity
font-size
knpmenubundle
underscore.js-templating
impresspages
make-install
hexdump
captivenetwork
ptrace
wapiti
tcpserver
reactive-banana
wireshark-dissector
citrus-pay
rgeo
sniffer
jsapi
lustre
sorl-thumbnail
ng-animate
html-helper
mesa
phpthumb
rebol3
expected-exception
ember-charts
mcts
pyhdf
jmapviewer
dataservice
padarn
seed
android-screen-support
eventlistener
trusted
dsn
automount
netbeans-6.9
gnu-prolog
pydot
coercion
imac
rescale
meego
iweb
gacutil
django-notification
3gp

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile