单击单选按钮更改android中的视图

单击单选按钮更改android中的视图,android,image,Android,Image,我有两个单选按钮,即一次和每天。当我点击一次,它将加载一个图像,当我点击另一个按钮,它将显示另一个静态图像。这一切工作正常。我通过获取单选按钮的id并设置背景资源,设计了带有图像加载的单选按钮。但是现在我对如何用编辑文本和按钮字段配置图像感到困惑。有人能帮我完成这个任务吗 public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.once) {

我有两个单选按钮,即一次和每天。当我点击一次,它将加载一个图像,当我点击另一个按钮,它将显示另一个静态图像。这一切工作正常。我通过获取单选按钮的id并设置背景资源,设计了带有图像加载的单选按钮。但是现在我对如何用编辑文本和按钮字段配置图像感到困惑。有人能帮我完成这个任务吗

public void onCheckedChanged(RadioGroup group, int checkedId) {

        if (checkedId == R.id.once) {
              int imageId = (Integer) once.getTag();

                imgview.setBackgroundResource(imageId);

        } else if (checkedId == R.id.daily) {
             int imageId = (Integer) daily.getTag();

                imgview.setBackgroundResource(imageId);

        } 
    } 

这是我的代码。现在我的要求是要访问单击单选按钮时加载的图像中的编辑文本字段和按钮字段。

我不确定我是否完全理解了您的问题。 是否要显示/隐藏文本视图和按钮而不是图像

如果是这样,只需创建一个包含textview和按钮的LinearLayout,然后设置属性

android:visibility="gone"
在LinearLayout标记中

然后,您可以通过代码设置其可见性:

LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayoutid);
ll.setVisibility(View.VISIBLE / View.GONE)

如果这不能回答您的问题,请向我们提供更多详细信息

如果您有ID,请尝试使用此选项

public void onCheckedChanged(RadioGroup group, int checkedId) {

    if (checkedId == R.id.once) {
          int imageId = (Integer) once.getTag();

            imgview.setBackgroundResource(imageId);
            EditText et = (EditText) imgview.findViewById(R.id.textFieldId);
            Button btn = (Button) imgview.findViewById(R.id.buttonId);

    } else if (checkedId == R.id.daily) {
         int imageId = (Integer) daily.getTag();

            imgview.setBackgroundResource(imageId);
            EditText et = (EditText) imgview.findViewById(R.id.textFieldId);
            Button btn = (Button) imgview.findViewById(R.id.buttonId);
    } 
} 
否则,您可以使用

EditText et = (EditText) imgview.getChildAt(0);
Button btn = (Button) = (Button ) imgview.getChildAt(1);
如果没有ID,请注意创建视图的顺序

如何修改线性布局背景

根据您的需要,将其放入onCheckedChanged、if或else块中:

LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayoutid);
ll.setVisibility(View.VISIBLE/View.GONE);
ll.setBackgroundResource(imageId);

您可以使用以下代码,这些代码非常适合我:

// declare your vars 
ImageView imgView;
Bitmap bitmap1,bitmap2;

// in your constructor do the following……
// load your bitmaps here
bitmap1 =  BitmapFactory.decodeResource(getResources(),R.drawable.bitmap1);
bitmap2 =  BitmapFactory.decodeResource(getResources(),R.drawable.bitmap2);

// init your image view
showImageView = new Imageview(getContext());


// AND IN YOUR LISTENER 
public void onCheckedChanged(RadioGroup group, int checkId){
    if(checkedId == R.id.once){
        imgView.setImageBitmap(bitmap1);
    }else if(checkedId == R.id.daily){
        imgView.setImageDrawable(bitmap2);
    }
}

请张贴您的代码。无法理解您的问题。你能简单介绍一下吗?访问edittext&button字段的问题是什么?事实上我每天都有单选按钮。当我点击一次时,一张图片可以被加载到每天的按钮。现在加载的图片必须包含textview和button。当我点击那个按钮时,它会显示picker。现在你们明白了吗?如果你仍然很困惑,让我知道你的意思。