我尝试在列表选择侦听器中使用edittext但它无法从主活动中看到它 把我带到这个错误
edt.setVisibility(View.VISIBLE);
所以,如果你有任何帮助我的话,那么请
public class MainActivity extends Activity {
static int HELLO_ID = 1;
boolean flag = false;
CountDownTimer timer;
//the strings of the notifications
String titlePills = "Time to take Panadol",DescriptionPills = "Panadol";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new SpinnerActivity());
Chronometer test = new Chronometer(this);
Button btn = (Button)findViewById(R.id.button1);
EditText edt = (EditText)findViewById(R.id.editText1);
//hide the button and the edit text
btn.setVisibility(View.GONE);
edt.setVisibility(View.GONE);
}
//*********************************************************************************
public class SpinnerActivity extends Activity implements OnItemSelectedListener {
public void onItemSelected(final AdapterView<?> parent, View view,
int pos, long id) {
String select = parent.getItemAtPosition(pos).toString();
if(select.equals("Type the timee"))
{
//edt error can't be resolved
edt.setVisibility(View.VISIBLE);
}
答案 0 :(得分:1)
试试这个..
EditText edt;
作为全局变量
edt = (EditText)findViewById(R.id.editText1);