【发布时间】:2019-12-09 18:12:09
【问题描述】:
我正在为一个博客应用程序编写代码,该应用程序将只发布文本或在其下方发布文本和图像。我在布局中定义了一个 editText 和一个 imageView。我想要那个,除非我点击画廊按钮,否则图像视图不会出现。
我是有意尝试的,但添加活动会使应用程序过于繁重。
private ImageButton newPostImgbtn;
private ImageView newPostImage;
private EditText newPostDesc;
private Button newPostBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.HomeTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
newPostImage = findViewById(R.id.imageView);
newPostImgbtn = findViewById(R.id.imageButton2);
newPostDesc = findViewById(R.id.editText);
newPostBtn = findViewById(R.id.button2);
}
我通过在图库 newimagebtn 的按钮上放置一个 onclick 侦听器创建了新的活动 imageactivity,仅用于添加图像,但我不想在另一个活动中执行此操作。
public void post(View v) { Intent intent = new Intent(postActivity.this,
imageActivity.class); startActivity(intent);}
此外,如果用户单击图库按钮,但未选择任何图像,则当单击发布按钮时,仅显示文本而没有空的图像视图区域或错误,因为该字段为空。请帮帮我。
【问题讨论】:
-
请多分享一些代码,理解不够
-
我是故意这样做的,我应该为此共享代码吗?我不明白这个问题的代码没有意图。
-
是的,请分享。
-
我创建了新的活动 imageactivity,通过在画廊 newimagebtn 的按钮上放置一个 onclick 侦听器来添加图像,但我不想在另一个活动中这样做。代码 > public void post(View v) { Intent intent = new Intent(postActivity.this, imageActivity.class);开始活动(意图);
-
然后只需使用 finish() ,它将支持您之前的活动
标签: java android android-layout android-intent