我有一個活動的主要和第二個活動。 活動主有3個文本視圖和一個按鈕,活動第二個有3個編輯文本一個按鈕和一個保存按鈕,第三個編輯文本是不可見的,當我按下按鈕編輯文本變得可見。如何獲取其他活動的編輯文本的可見性結果?
我的問題是,如何獲得該編輯文本的可見性狀態? 我想要顯示的結果時,它是可見的,並TextView的可見 我也希望它是無形的當次活動的按鈕未按
我在活動主當前代碼
// This method opens the second activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from activity.xml
setContentView(R.layout.activity_main);
// Locate the button in activity_main.xml
btn1 = (Button)findViewById(R.id.Open_Form);
// Capture button clicks
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Start SecondActivity.class for result
Intent myIntent3 = new Intent(MainActivity.this,
SecondActivity.class);
startActivityForResult(myIntent3, ACTIVITY_RESULT_CODE);
}
});
// This method is called when second activity finishes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Check that it is the second activity with an OK result
if (requestCode == ACTIVITY_RESULT_CODE) {
if (resultCode == RESULT_OK) {
// Get string data from Intent
String Brand = data.getStringExtra("@id/etBrand");
// Set text view with string
TextView tvBrand = (TextView)findViewById(R.id.tvBrand);
tvBrand.setText(Brand);
tvBrand.getVisibility();{
String Name = data.getStringExtra("@id/etName");
TextView tvName = (TextView)findViewById(R.id.tvName);
tvName.setText(Name);
tvName.getVisibility();{
String Size = data.getStringExtra("@id/etSize");
TextView tvSize = (TextView)findViewById(R.id.tvSize);
tvSize.setText(Size);
tvSize.getVisibility();{
}
}
}
}
}
我的第二個活動代碼
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rod_dialog1);
EditText etSize = (EditText)findViewById(R.id.etSize);
etSize.setVisibility(View.INVISIBLE);
Button button2 = (Button)findViewById(R.id.Add_Size);
button2.setVisibility(View.VISIBLE);
// Create the submit button
btn1 = (Button)findViewById(R.id.bSave);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Get the text from EditText and put the string to pass back into an Intent
EditText etBrand = (EditText)findViewById(R.id.etBrand);
String stringToPassBack = etBrand.getText().toString();
Intent myIntent1 = getIntent();
myIntent1.putExtra("@id/etBrand", stringToPassBack);
// Get the text and put the string to pass back into an Intent
EditText etName = (EditText)findViewById(R.id.etName);
String stringToPassBack1 = etName.getText().toString();
Intent myIntent2 = getIntent();
myIntent2.putExtra("@id/etName", stringToPassBack1);
// Get the text and put the string to pass back into an Intent
EditText etSize = (EditText)findViewById(R.id.etSize);
String stringToPassBack2 = etSize.getText().toString();
Intent myIntent3 = getIntent();
myIntent3.putExtra("@id/etSize", stringToPassBack2);
// Close activity
setResult(RESULT_OK_1, myIntent1);
finish();
}
});
btn2 = (Button)findViewById(R.id.Add_Size);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText etSize = (EditText)findViewById(R.id.etSize);
etSize.setVisibility(View.VISIBLE);
Button button2 = (Button)findViewById(R.id.Add_Size);
button2.setVisibility(View.INVISIBLE);
}
});
}
您檢查RESULT_OK但你的setResult的RESULT_OK_1。 – RonTLV
這是一個打字錯誤。 –