コードが長すぎるため、すべてのコードをコピーしているわけではありませんが、簡潔にするために:
私は、インターネット (XML) からデータを取得し、それをデコードし、各「ノード」をアダプターの要素に割り当てるスレッドを含む関数 (recup_list_internet) を持っています。
スレッドの外でデコードを行うと、すべて正常に動作します。したがって、これをスレッド内で使用するように変更し、その中に void run() 関数を作成し、progressDialog を表示し、デコードし、データが適切に取得され、マップ (=new HashMap();) に適切に割り当てられます。問題が発生
private void recup_list_internet()
{
final ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
final Context mContext=this.getBaseContext();
Thread t = new Thread()
{
public void run()
{/* the code here works fine, not displaying it to be more concise*/
progressDialog.dismiss(); //works fine
SimpleAdapter mSchedule = new SimpleAdapter (mContext, listItem, R.layout.affiche_boutique,new String[] {"img", "titre", "description","Prix","uniqueID"}, new int[] {R.id.img,R.id.titre, R.id.description,R.id.prix,R.id.uniqueID}); //works fine
maListViewPerso.setAdapter(mSchedule); //doesn't work
}
};
t.start();
}
これが私の丸太猫です:
11-04 19:20:33.070: E/recuperation phonster(546): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
スレッド内で maListViewPero に「アクセス」できないようです... (maListViewPerson は、私の onCreate コードで以前に定義されています:
public class DisplayInternet extends Activity{
private ListView maListViewPerso;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.ceinture_lv);
maListViewPerso = (ListView) findViewById(R.id.listviewperso);
recup_list_internet();
}
では、この行をどこに置くことができますか?"maListViewPerso.setAdapter(mSchedule);"
私はすでにスレッドの外側で mSchedule を宣言しようとしていますが (最終的に)、スレッドの内側ではアクセスできません (したがって、「t.start()」行の後に使用することはできません)