gpt4 book ai didi

java - 如何通过选择微调器来启用或禁用 editText

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:37 24 4
gpt4 key购买 nike

问题是它会禁用文本编辑,但在开关的情况 1 中,当您必须再次激活它时,它不会禁用

这是我正在使用的代码。

public class ejemolo extends AppCompatActivity {

String[] Items = {
"Dc amps a Kw",
"Ac una fase amp a kw ",
"Ac trifasicaamps a kw (linia a linea de voltaje)",
"Ac trifasica amps a kw (linia a voltaje neutral)",

};

Spinner s1;

private String[] listOfObjects;

EditText ampEditText , voltageEditText , powerfactorEditText ;

TextView text1 , text2 , text3, text4 ;

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ejemolo);

FloatingActionButton buttonback = (FloatingActionButton)findViewById(R.id.floatingActionButtonback);
buttonback.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext() , Weight.class);
startActivityForResult(intent ,0);
}
});

FloatingActionButton buttonhome = (FloatingActionButton)findViewById(R.id.floatingActionButtonhome);
buttonhome.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext() , MainActivity.class);
startActivityForResult(intent ,0);
}
});

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

s1 = (Spinner) findViewById(R.id.spinnerAmp);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Items);

s1.setAdapter(adapter);

ampEditText = (EditText)findViewById(R.id.ampEditText);
voltageEditText = (EditText)findViewById(R.id.voltageEditText);

powerfactorEditText = (EditText)findViewById(R.id.powerfactorEditText);

//text1=(TextView)findViewById(R.id.tonsTextResult1);
//text2=(TextView)findViewById(R.id.tonsTextResult2);

listOfObjects = getResources().getStringArray(R.array.object_array4);

// final Spinner spinner = (Spinner)findViewById(R.id.spinnerAmp);

final android.icu.text.DecimalFormat decimals = new android.icu.text.DecimalFormat("0.00"); /** la cantidad de digitos decimales que se muestra */

// ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_item, listOfObjects);

s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

switch (position) {

case 0 :

int indzex = s1.getSelectedItemPosition();
powerfactorEditText.setFocusable(false);
powerfactorEditText.setEnabled(false);
powerfactorEditText.setCursorVisible(false);
powerfactorEditText.setKeyListener(null);
powerfactorEditText.setBackgroundColor(Color.TRANSPARENT);

break;

case 1:

int index = s1.getSelectedItemPosition();
powerfactorEditText.setEnabled(true);
powerfactorEditText.setInputType(InputType.TYPE_CLASS_TEXT);
powerfactorEditText.setFocusable(true);
powerfactorEditText.setCursorVisible(true);

break;

}

}

@Override
public void onNothingSelected(AdapterView<?> f
}

}

我想在微调器案例 2 中启用该问题..

最佳答案

由于案例 0 中的这一行,您无法启用 EditText:powerfactorEditText.setKeyListener(null);

请删除此行并进行测试,否则设置正确的 Keylistener。

引用以下链接: Edit Text key listener

关于java - 如何通过选择微调器来启用或禁用 editText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43947459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com