は次は私のコードです:基本的に私は、ボタンのリスナーからそれを実行するために進捗クラスを呼び出すと私は、このエラーImはボタンイベントからプライベートクラスを呼び出すようにしようと、私はjava.lang.RuntimeExceptionを得る:
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
を取得
ボタンやメニューからこの進捗クラスを実行する方法はありますか?あなたがバックグラウンドスレッドからUIを変更しようとしている
public class ProgressDialogeActivity extends Activity {
private ProgressDialog dialog;
int count = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// running from main activity
dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("Deleteng Contacts ...");
dialog.setMax(50);
// dialog.show();
// dialog.setProgress(40);
Object Maxmssg = checkhowmanysms();
// dialog.setMax((Integer) Maxmssg);
Button deletesms = (Button) findViewById(R.id.button1);
deletesms.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
progress prog = new progress();
prog.start();
}
});
}
public class progress extends Thread {
@Override
public void run() {
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("Deleteng Contacts ...");
int size = checkhowmanysms();
Object Maxmssg = checkhowmanysms();
dialog.setMax((Integer) Maxmssg);
dialog.show();
Uri inboxUri = Uri.parse("content://sms");
Cursor item = getContentResolver().query(inboxUri, null, null,
null, null);
while (item.moveToNext()) {
count++;
dialog.setProgress(count);
// Delete the SMS
String pid = item.getString(0); // Get id;
String uri = "content://sms";
getContentResolver().delete(Uri.parse(uri), null, null);
}
dialog.dismiss();
}
}
正しいアクセス権を追加しましたか? [許可] [1] [1]:http://stackoverflow.com/questions/9616476/delete-sms-from-smstable-in-android – Oglop