我的 Android 应用程序有问题,我的应用程序是ProgressDialog
为显示计算数据而构建的,但没有使用“睡眠”
但是该计算的数据结果没有显示
我想用 TextView 和 Listview 显示数据
消息错误是only the original thread that created a view hierarchy can touch its views
这是我的代码:
progressDialog = ProgressDialog.show(hasilrute.this, "","Communicating",true);
new Thread(new Runnable() {
@Override
public void run() {
cariRute(tv);
try {
} catch (Exception e) {
// TODO: handle exception
}
handler.sendEmptyMessage(0);
progressDialog.dismiss();
}
}).start();
progressDialog.dismiss();
Handler handle=new Handler(){
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what == 0) {
//perform some action here................
}
}
};
这是我的cariRute
方法:
public void cariRute(TextView t){
String haha = tv.getText().toString().toLowerCase();
String []getAsalTujuan = haha.split("-");
getAsal = getAsalTujuan[0];
getTujuan = getAsalTujuan[1];
cari(getAsal,getTujuan);
route = new ArrayList<rute>();
for(int i=0;i<hasilKahir.size()-1;i++){
a = hasilKahir.get(i);
i++;
b = hasilKahir.get(i);
i--;
hitungJarak(a, b);
System.out.println(a+b);
List<rute> temp = new ArrayList<rute>();
temp = getDataRute(a,b);
/*temp = getDataRute(a,b);
for(int j = 0; j < temp.size(); j++){
route.add(temp.get(j));
}*/
}
List<rute> temp = new ArrayList<rute>();
temp = filterList(listJalan);
route = temp;
jrk = 0;
for(int k = 0;k<Ljrk.size();k++){
jrk = jrk + Ljrk.get(k);
}
//System.out.println(jrk);
ongkos = 0;
for(int l = 0;l<Longkos.size();l++){
ongkos = ongkos + Longkos.get(l);
//System.out.println(ongkos);
}
pembulatan("####.##", jrk);
hitungOngkos(ongkos);
System.out.println(jrk+ongkos);
JARAK = (TextView)findViewById(R.id.textView11);
JARAK.setText(" Jarak : "+keluaran+" km");
ONGKOS = (TextView)findViewById(R.id.textView12);
ONGKOS.setText(" Ongkos : Rp."+harga);
Longkos.clear();
for(int x = 0; x < route.size();x++){
}
ListAdapter adapter = new ruteListAdapter(this, (List<? extends Map<String, String>>) route,
R.layout.list_item_2, new String[] {
rute.ANGKOT, rute.JALAN }, new int[] {
R.id.textID, R.id.textRute });
this.setListAdapter(adapter);
//db.close();
}
这是我的ruteListAdapter
课:
private List<rute> route;
private int[] colors = new int[] { 0x30ffffff, 0x30808080 };
@SuppressWarnings("unchecked")
public ruteListAdapter(Context context,
List<? extends Map<String, String>> route,
int resource,
String[] from,
int[] to) {
super(context, route, resource, from, to);
this.route = (List<rute>) route;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
return view;
}
谁能帮我解决我的问题?