내 응용 프로그램은 CallLog를 사용하여 데이터를 수집하고이를 listview에 저장합니다. 시간이 걸리므로 progressdialog를 사용하여 사용자에게로드 상태를 표시하려고했습니다. 불행히도 (나는 progressdialog를 사용했다.) 이클립스는 나를 에러로 던진다 : ERROR/AndroidRuntime (771) : android.view.ViewRoot $ CalledFromWrongThreadException : 뷰 계층 구조를 생성 한 원래 스레드 만 뷰를 만질 수있다.안드로이드 progressdialog 스레드 예외
public class Calls extends Activity {
//declaring variables
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calls);
lv1 = (ListView) findViewById(R.id.ListView01);
pd = new ProgressDialog(Calls.this);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMessage("Loading contacts");
pd.show();
//Thread thread = new Thread() {
//public void run() {
Calls.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//collecting data from CallLog, putting data into an array
//Here comes the hard part, which is the root of the problem:
final ArrayList<SearchResults> results = new ArrayList<SearchResults>();
SearchResults sr1 = new SearchResults();
for (int b=0; b<storage.length; b++)
{
for (int e=0; e<storage[b].length; e++)
{
if (e+3 < storage[b].length)
{
arr_split_all.add(storage[b][e] + " " + storage[b][e+1] + " " + storage[b][e+2] + " " + storage[b][e+3]);
sr1 = new SearchResults();
sr1.setData1(storage[b][e+2]);
sr1.setData2(storage[b][e]);
sr1.setData3(storage[b][e+1]);
sr1.setData4(storage[b][e+3]);
sr1.setBitmap2(bitmaparray[b]); //bitmaparray has the same size as storage, and there is no problem with this
results.add(sr1);
}
}
}
lv1.setAdapter(new MyCustomBaseAdapter(Calls.this, results)); //problematic row
handler.sendEmptyMessage(0);
}
};
thread.start();
}
}//end of onCreate
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();
}
}); //ADDED a)
}//end of class
// SearchResults is another class:
public class SearchResults extends Application{
private String data1 = "";
private String data2 = "";
private String data3 = "";
private String data4 = "";
private String bitmap = "";
private Bitmap bitmap2;
public void setData1(String data1) {
this.data1 = data1;
}
public String getData1() {
return data1;
}
//etc...
}
내가 (이미지 뷰와 네 textviews 구성) 목록보기의 적절한 위치에 데이터를 넣어 BaseAdapter 클래스를 사용하고,하지만 난 그게 지금 관련이 있다고 생각하지 않습니다.
Logcat에 따르면이 문제는 lv1.setAdapter(new MyCustomBaseAdapter(Calls.this, results));
행에 있습니다. arraylist를 listview에 첨부하면 정상적으로 작동합니다. progressdialog가 없으면 모든 textviews와 listview의 각 행의 이미지 뷰가 올바르게로드됩니다.