@Override // ListView内のボタンのイベント処理 protected void onListItemClick(ListView lv, View v, int pos, long id) { super.onListItemClick(lv, v, pos, id); CustomData item = (CustomData) lv.getItemAtPosition(pos); // いいねボタンが押された場合 if (id == 0) { // user_idとcomment_idを取得してAPIを叩く iineTask = new IineTask(this, item); iineTask.execute(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } task = new ListTask(lv, this); task.execute(); // コメント欄ボタンが押された場合 } else if (id == 1) { ImageCache.clearCache(); Intent intent = new Intent(ImageTwActivity.this, CommentActivity.class); intent.putExtra("commentId", item.getCommentId()); intent.putExtra("comment", item.getTitleName()); startActivity(intent); } }
// 端末の向きを変えた際、AsyncTask原因のクラッシュ防止 @Override protected void onPause() { if (ListTask.pd != null && ListTask.pd.isShowing()) { ListTask.pd.dismiss(); ListTask.pd = null; } if (IineTask.pd != null && IineTask.pd.isShowing()) { IineTask.pd.dismiss(); IineTask.pd = null; } if (task != null && task.isCancelled()) { task.cancel(true); } if (iineTask != null && iineTask.isCancelled()) { iineTask.cancel(true); } super.onPause(); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* //デバッグ用のコード StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .penaltyDeath() .build());*/ // StrictModeを設定 penaltyDeathを取り除く StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); // 撮影ボタンとかその辺の設定 setContentView(R.layout.main); Button bt = (Button) findViewById(R.id.button1); Button local = (Button) findViewById(R.id.button2); Button reload = (Button) findViewById(R.id.reload); lv = (ListView) findViewById(android.R.id.list); task = new ListTask(lv, this); task.execute(); bt.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ImageCache.clearCache(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, REQUEST_CAPTURE_IMAGE); } }); // ローカルアップロード local.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ImageCache.clearCache(); Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, REQUEST_CODE); } }); reload.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ImageCache.clearCache(); task = new ListTask(lv, ImageTwActivity.this); task.execute(); } }); }