我有三个一段代码RadioButton
中A S RadioGroup
.我想设置的onCheckedListener
,将显示的值RadioButton
的Toast
.然而,到目前为止,我所得到的并不奏效.如何获取RadioButton
并显示它的值Toast
?提前谢谢,这是我的代码:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
RadioGroup rg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
final String value =
((RadioButton)findViewById(rg.getCheckedRadioButtonId()))
.getText().toString();
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
Toast.makeText(getBaseContext(), value, Toast.LENGTH_SHORT).show();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
XML文件:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" …
Run Code Online (Sandbox Code Playgroud) 我的代码没有给出错误,但它没有显示最小值和最大值.代码是:
Scanner input = new Scanner(System.in);
int array[] = new int[10];
System.out.println("Enter the numbers now.");
for (int i = 0; i < array.length; i++) {
int next = input.nextInt();
// sentineil that will stop loop when 999 is entered
if (next == 999) {
break;
}
array[i] = next;
// get biggest number
getMaxValue(array);
// get smallest number
getMinValue(array);
}
System.out.println("These are the numbers you have entered.");
printArray(array);
// getting the maximum value
public static int getMaxValue(int[] array) {
int …
Run Code Online (Sandbox Code Playgroud) 我这里有这段代码:
Scanner input = new Scanner(System.in);
int array[] = new int[10];
System.out.println("Enter the numbers now.");
for (int i = 0 ; i < array.length; i++ ) {
if (input.nextInt() == 999){
break;
} else {
array[i] = input.nextInt();
}
}
Run Code Online (Sandbox Code Playgroud)
如果用户在阵列中输入999,我想打破循环,但到目前为止没有运气.我尝试使用break或返回false但没有任何作用.有没有人有办法解决吗?非常感谢!