今天下午写了一下午的程序,怎么看都没有任何错误,服务器端运行正确,客户端一直有问题。
排查了各种可能的错误之后,我想到是不是应该用线程(一遇到线程头就大)。
由于是对listview中的某一个item中的按钮控件进行监听的事件,单独用线程是不可能实现的。
后来发现一个可行的办法,和大家分享一下。
在我的例子中
对于botton事件的监听
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
。。。。。(写自己的代码) } }
或者如果你的程序可以使用线程的话,也是可行的。
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton) {
JSONObject bill_json = null;
String is_feename= name.getText().toString();
String is_freightmemo=freightmemo.getText().toString();
String is_freightmemodownload= freightmemodownload.getText().toString();
String is_fipid=t_fipid.getText().toString();
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());