あなたのクラスでxmlファイルのidを呼び出します
-
25-09-2019 - |
質問
私は画像の表示は、ボタンクリック時に、その中に絵を持っているかどうかを検出するにはどうすればよいです。私は表示された画像およびいくつかの結果というクラスがあったが、結果はそのクラスに書き込まれるまで、私は(ボタンを押す)、ユーザはそれらの結果にアクセスできるようにしたくない。
だから、私はまだImageViewの中に表示される画像があったかどうかを確認するために必要な考え出します。
だから、何かのように:
case R.id.previous_box:
if (R.id.photoResultView == null){
//throw up a dialog box saying they need to snap a pic first.
}
Intent j = new Intent(DTF.this, Result.class);
startActivity(j);
return;
しかしobviouslt R.id.photoResultView == nullでそれを行うには正しい方法ではありません...誰のノウハウ?
タンク!
EDIT:ライン184
if (photoResultView.getDrawable() == null) {
EDITます:
case R.id.previous_box:
if (photoResultView.getDrawable() == null) {
showToast(DTF.this, "You have to take a picture first");
return;
}
Intent j = new Intent(main.this, Result.class);
startActivity(j);
return;
解決
この、代わりにあなたが現在持っているif
ブロックの、試してみてください
ImageView photoResultView = (ImageView)findViewById(R.id.photoResultVew);
if (photoResultView.getDrawable() == null) {
//throw dialog
}
ImageView.getDrawable()
に戻る描画領域のいずれか、またはヌル(無Drawableのセットが存在しない場合)。
は基本的に、あなたはこのような何かを持っていると言います
public class HelloAndroid extends Activity {
ImageView photoResultView; //this creates a class variable
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//this assigns it to the photoResultView you defined in your XML
photoResultView = (ImageView)findViewById(R.id.photoResultView);
}
}
他のヒント
public class MyActivity extends Activity {
private ImageView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_records);
imageView = (ImageView) findViewById(R.id.image_view);
}
}
所属していません StackOverflow