我动态地在一个无线电组中创建了两个单选按钮,并检查其中一个.我需要当我扯下另一个按钮然后它的值应保存在字符串中.但我已经实现了这一点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) 我正在实现如果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)