ProgressBar를 사용하려고합니다. ProgressBar는 로컬 자산 폴더에있는 데이터베이스 로딩 진행률을 보여줍니다. 나는 인터넷에서 파일을 다운로드하기 전에 있었던 코드를 사용하고 있기 때문에 이런 식으로 가능한지 모르겠습니다.데이터베이스로드 - 진행률을 표시하는 방법 바?
나는 데이터베이스의 크기를 가져야한다고 생각하지만, 어떻게해야할지 모르겠다. conection.getContentLength()가 작동하지 않는 것 같습니다. 연결 부분에 주소 자산/kneipen2.sqlite가 포함되지 않았습니까?
이
은에서 onCreate()에 있습니다new LoadFilesTask().execute("assets/kneipen2.sqlite");
그리고 이것은 AsyncTask를 내부 클래스입니다 :
private class LoadFilesTask extends AsyncTask<String, Integer, Integer> {
@Override
protected Integer doInBackground(String... urls) {
//oeffneDatenbank();
int count;
try {
myDbHelper = new DataBaseHelper(Start.this);
try {
myDbHelper.createDataBase();
}
catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
URL url = new URL(urls[0]);
//Ignore this! Only used to show that operations can take a long time to complete...
URLConnection conection = url.openConnection();
conection.connect();
int lenghtOfFile = conection.getContentLength();
// downlod File
InputStream input = new BufferedInputStream(url.openStream());
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
publishProgress((int)(total*100/lenghtOfFile));
}
input.close();
} catch (Exception e) {}
return null;
}
그래서, 진행이 표시되지 않습니다, 그러나 결국 데이터베이스에서 올바르게로드되었습니다. 도와주세요.
예, 당신이 말한 것을 고맙게 생각합니다. 그리고 그것은 아주 잘 작동합니다. 그래서,이 솔루션은 좋은 해결책이고, 작동하지만, 가능하다면 나는 레이아웃의 이유로 여전히 progressBar가 로컬 파일을로드하는 진행 상황을 보여주기를 원합니다. 그게 가능하니? 그렇지 않다면 진행 대화 상자의 모양에 영향을 미치는 방법이 있습니까? – 10ff