目前我試圖在運行時顯示圖像,但每當android應用程序正在讀取,然後通過從activity_main.xml文件讀取自動顯示圖像。在android中按鈕單擊後顯示圖像
我想在同一活動頁面中顯示我的結果圖像。
activity_main.xml中
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_margin="5dp"
android:src="@drawable/friendship"
android:contentDescription="@string/desc1"/>
MainActivity.java
private void onSaveClick(){
String res,fname,sname;
TestRelation tr = new TestRelation();
Validations validate = new Validations();
TextView text = (TextView) findViewById(R.id.tv);
EditText firstname = (EditText)findViewById(R.id.first_name);
EditText secondname = (EditText)findViewById(R.id.second_name);
fname = firstname.getText().toString();
sname = secondname.getText().toString();
if(validate.validate(fname, sname).equals("")){
res = tr.checkRelation(fname, sname);
text.setText(res);
}else{
text.setText(validate.validate(fname, sname));
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageResource(R.drawable.friendship);
}
//System.out.println("res value"+res);
}
在圖像被點擊提交按鈕之前顯示上面的代碼。 點擊提交按鈕後,請幫助我在同一活動頁面中顯示圖像。