小编ami*_*ita的帖子

当单选按钮选中状态更改时,如何从单选按钮中的单选按钮获取文本

我动态地在一个无线电组中创建了两个单选按钮,并检查其中一个.我需要当我扯下另一个按钮然后它的值应保存在字符串中.但我已经实现了这一点checkedchangelistener.但它没有第一次工作.这是我的代码.

rg = ((RadioGroup)getActivity().findViewById(alist_id.get(i)));
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
    public void onCheckedChanged(RadioGroup rd, int checkedId) {
        for(int i=0; i<rd.getChildCount(); i++) {
            radio_button = (RadioButton) rd.getChildAt(i);
            int id = radio_button.getId();
            if(radio_button.getId() == checkedId) {
                text = radio_button.getText().toString();
                flag=true;
                System.out.println("trueeeeeeeee"+text);
                return;
            }
        }
    }
});
if (flag==true) {
    updated_list.add(text);
    System.out.println("sssssssssssssssssss");
}else {
    updated_list.add(data_from_list_view.get(i));
    System.out.println("falseeeeeee");
}
Run Code Online (Sandbox Code Playgroud)

java android radio-button

6
推荐指数
2
解决办法
3万
查看次数

如何检查ImageView是否包含位图?

我正在实现如果ImageView有位图然后它应该将图像从imageview保存到内部存储器,否则在应用程序的内部存储器中设置另一个位图.这是代码:_

 croppedImage = cropImageView.getCroppedImage();
                 croppedImageView = (ImageView) findViewById(R.id.croppedImageView);
                croppedImageView.setImageBitmap(croppedImage);@Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.btn_save:
            counter++;
            if(croppedImageView.getDrawable() != null)
            {
                System.out.println("nullllllllllllll");

                try {
                    Bitmap photo = ((BitmapDrawable)croppedImageView.getDrawable()).getBitmap();
                    FileOutputStream mFileOutStream1 = openFileOutput("IMG" + counter + ".png", Context.MODE_PRIVATE);
                    photo.compress(CompressFormat.JPEG, 100, mFileOutStream1);} 
                catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();}
                }else{
                  System.out.println("notttttnullllllllllllll");
                  try {
                     FileOutputStream mFileOutStream1 = openFileOutput("IMG" + counter + ".png", Context.MODE_PRIVATE);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, mFileOutStream1);
                  } catch (FileNotFoundException e) …
Run Code Online (Sandbox Code Playgroud)

java android drawable android-camera android-imageview

4
推荐指数
1
解决办法
2万
查看次数