Update Textview inside for and while loop











up vote
-2
down vote

favorite












i have a structure of code that looks like this



for () {
while(){

}

while(){

}

while(){

}

while(){

}
}


focus on those while my target is to update a textview when those while is moving. what should i do?



What i mean is this here is my entire code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {

if (count_row(FilePathname_SAMPLE) != 0) {
myDb.delete_customer(current_email);

Thread thread;
final Handler handler = new Handler();
thread = new Thread(new Runnable() {
public void run() {
int index = 0;
CsvRow row;
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9)
);

index++;
float p = (float)index / (float)row_count;
p = p * (float)100;


handler.post(new Runnable() {
public void run() {
counter_load.setText((int)p);
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
});
thread.start();
}
}


my target is to update the textview inside the while loop



Please see my updated code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
Thread thread;
final Handler handler = new Handler();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {
CsvRow row;
if (count_row(FilePathname_CUS) != 0) {
myDb.delete_customer(current_email);
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9),
row.getField(10)
);
Log.e("Inserting", "" + row.getField(0));
index++;
p = (float) index / (float) row_count;
p = p * (float) 100;
handler.post(new Runnable() {
public void run() {
counter.setText((String.valueOf(p)));
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

} else {

}
}









share|improve this question
























  • post you code first.
    – Ali Ahmed
    Nov 8 at 11:37










  • What do you mean by while is moving?
    – gratien asimbahwe
    Nov 8 at 11:37










  • please see my updated post
    – myown email
    Nov 8 at 11:42










  • so whatsa your issue?
    – Alesandro Giordano
    Nov 8 at 11:46










  • my textview doest update any text while inside the loop
    – myown email
    Nov 8 at 11:47















up vote
-2
down vote

favorite












i have a structure of code that looks like this



for () {
while(){

}

while(){

}

while(){

}

while(){

}
}


focus on those while my target is to update a textview when those while is moving. what should i do?



What i mean is this here is my entire code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {

if (count_row(FilePathname_SAMPLE) != 0) {
myDb.delete_customer(current_email);

Thread thread;
final Handler handler = new Handler();
thread = new Thread(new Runnable() {
public void run() {
int index = 0;
CsvRow row;
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9)
);

index++;
float p = (float)index / (float)row_count;
p = p * (float)100;


handler.post(new Runnable() {
public void run() {
counter_load.setText((int)p);
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
});
thread.start();
}
}


my target is to update the textview inside the while loop



Please see my updated code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
Thread thread;
final Handler handler = new Handler();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {
CsvRow row;
if (count_row(FilePathname_CUS) != 0) {
myDb.delete_customer(current_email);
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9),
row.getField(10)
);
Log.e("Inserting", "" + row.getField(0));
index++;
p = (float) index / (float) row_count;
p = p * (float) 100;
handler.post(new Runnable() {
public void run() {
counter.setText((String.valueOf(p)));
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

} else {

}
}









share|improve this question
























  • post you code first.
    – Ali Ahmed
    Nov 8 at 11:37










  • What do you mean by while is moving?
    – gratien asimbahwe
    Nov 8 at 11:37










  • please see my updated post
    – myown email
    Nov 8 at 11:42










  • so whatsa your issue?
    – Alesandro Giordano
    Nov 8 at 11:46










  • my textview doest update any text while inside the loop
    – myown email
    Nov 8 at 11:47













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











i have a structure of code that looks like this



for () {
while(){

}

while(){

}

while(){

}

while(){

}
}


focus on those while my target is to update a textview when those while is moving. what should i do?



What i mean is this here is my entire code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {

if (count_row(FilePathname_SAMPLE) != 0) {
myDb.delete_customer(current_email);

Thread thread;
final Handler handler = new Handler();
thread = new Thread(new Runnable() {
public void run() {
int index = 0;
CsvRow row;
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9)
);

index++;
float p = (float)index / (float)row_count;
p = p * (float)100;


handler.post(new Runnable() {
public void run() {
counter_load.setText((int)p);
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
});
thread.start();
}
}


my target is to update the textview inside the while loop



Please see my updated code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
Thread thread;
final Handler handler = new Handler();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {
CsvRow row;
if (count_row(FilePathname_CUS) != 0) {
myDb.delete_customer(current_email);
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9),
row.getField(10)
);
Log.e("Inserting", "" + row.getField(0));
index++;
p = (float) index / (float) row_count;
p = p * (float) 100;
handler.post(new Runnable() {
public void run() {
counter.setText((String.valueOf(p)));
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

} else {

}
}









share|improve this question















i have a structure of code that looks like this



for () {
while(){

}

while(){

}

while(){

}

while(){

}
}


focus on those while my target is to update a textview when those while is moving. what should i do?



What i mean is this here is my entire code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {

if (count_row(FilePathname_SAMPLE) != 0) {
myDb.delete_customer(current_email);

Thread thread;
final Handler handler = new Handler();
thread = new Thread(new Runnable() {
public void run() {
int index = 0;
CsvRow row;
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9)
);

index++;
float p = (float)index / (float)row_count;
p = p * (float)100;


handler.post(new Runnable() {
public void run() {
counter_load.setText((int)p);
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
});
thread.start();
}
}


my target is to update the textview inside the while loop



Please see my updated code



File file = new File(FilePathname_CUS);
CsvReader csvReader = new CsvReader();
Thread thread;
final Handler handler = new Handler();
try (CsvParser csvParser = csvReader.parse(file, StandardCharsets.UTF_8)) {
CsvRow row;
if (count_row(FilePathname_CUS) != 0) {
myDb.delete_customer(current_email);
while ((row = csvParser.nextRow()) != null) {
myDb.insert_customer(
row.getField(0),
row.getField(1),
row.getField(2),
row.getField(3),
row.getField(4),
row.getField(5),
row.getField(6),
row.getField(7),
row.getField(8),
row.getField(9),
row.getField(10)
);
Log.e("Inserting", "" + row.getField(0));
index++;
p = (float) index / (float) row_count;
p = p * (float) 100;
handler.post(new Runnable() {
public void run() {
counter.setText((String.valueOf(p)));
}
});
try {
// Sleep for 100 milliseconds.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

} else {

}
}






android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 12:04

























asked Nov 8 at 11:28









myown email

347




347












  • post you code first.
    – Ali Ahmed
    Nov 8 at 11:37










  • What do you mean by while is moving?
    – gratien asimbahwe
    Nov 8 at 11:37










  • please see my updated post
    – myown email
    Nov 8 at 11:42










  • so whatsa your issue?
    – Alesandro Giordano
    Nov 8 at 11:46










  • my textview doest update any text while inside the loop
    – myown email
    Nov 8 at 11:47


















  • post you code first.
    – Ali Ahmed
    Nov 8 at 11:37










  • What do you mean by while is moving?
    – gratien asimbahwe
    Nov 8 at 11:37










  • please see my updated post
    – myown email
    Nov 8 at 11:42










  • so whatsa your issue?
    – Alesandro Giordano
    Nov 8 at 11:46










  • my textview doest update any text while inside the loop
    – myown email
    Nov 8 at 11:47
















post you code first.
– Ali Ahmed
Nov 8 at 11:37




post you code first.
– Ali Ahmed
Nov 8 at 11:37












What do you mean by while is moving?
– gratien asimbahwe
Nov 8 at 11:37




What do you mean by while is moving?
– gratien asimbahwe
Nov 8 at 11:37












please see my updated post
– myown email
Nov 8 at 11:42




please see my updated post
– myown email
Nov 8 at 11:42












so whatsa your issue?
– Alesandro Giordano
Nov 8 at 11:46




so whatsa your issue?
– Alesandro Giordano
Nov 8 at 11:46












my textview doest update any text while inside the loop
– myown email
Nov 8 at 11:47




my textview doest update any text while inside the loop
– myown email
Nov 8 at 11:47

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206837%2fupdate-textview-inside-for-and-while-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206837%2fupdate-textview-inside-for-and-while-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff