![](/img/trans.png)
[英]I want outlined text field with as shown in picture not clicked on edittext or spinner i want same as it is view on Button click
[英]I want to let the data to be shown on the edittext
我想讓數據首先顯示在edittext上。 我該怎么做? 我已經將數據傳遞到了修改頁面,我想讓數據首先顯示在edittext上,然后在用戶需要更改時讓用戶更改標題。
這是我的修改頁面代碼:
public class MeTodolistModify extends AppCompatActivity implements View.OnClickListener {
private String student_id,student_name,title,input;
private EditText addtext;
private Button change;
private int position;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_me_todolist_modify);
Bundle bundle = getIntent().getExtras();
title = bundle.getString("title");
position = bundle.getInt("position");
student_id = bundle.getString("student_id");
student_name = bundle.getString("student_name");
createDetail();
}
private void createDetail(){
final FirebaseDatabase db = FirebaseDatabase.getInstance();
final DatabaseReference ref = db.getReference("Student").child(student_id).child("event");
Log.e("MOD",String.valueOf(position));
Log.e("MOD2",title);
change = findViewById(R.id.change);
change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText addtext = findViewById(R.id.addtext);
input = addtext.getText().toString();
ref.child(Integer.toString(position)).setValue(input);
Intent intent;
switch (v.getId()) {
case R.id.change:
intent = new Intent(MeTodolistModify.this, MeTodolist.class);
intent.putExtra("student_id", student_id );
intent.putExtra("student_name",student_name);
startActivity(intent);
break;
}
}
});
}
@Override
public void onClick(View v) {
}
}
修改頁面的更新代碼:
public class MeTodolistModify extends AppCompatActivity implements View.OnClickListener {
private String student_id,student_name,title,input;
private EditText addtext;
private Button change;
private int position;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_me_todolist_modify);
Bundle bundle = getIntent().getExtras();
title = bundle.getString("title");
position = bundle.getInt("position");
student_id = bundle.getString("student_id");
student_name = bundle.getString("student_name");
createDetail();
}
private void createDetail(){
final FirebaseDatabase db = FirebaseDatabase.getInstance();
final DatabaseReference ref = db.getReference("Student").child(student_id).child("event");
Log.e("MOD",String.valueOf(position));
Log.e("MOD2",title);
change = findViewById(R.id.change);
change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText addtext = findViewById(R.id.addtext);
addtext.setText(title);
input = addtext.getText().toString();
ref.child(Integer.toString(position)).setValue(input);
Intent intent;
switch (v.getId()) {
case R.id.change:
intent = new Intent(MeTodolistModify.this, MeTodolist.class);
intent.putExtra("student_id", student_id );
intent.putExtra("student_name",student_name);
startActivity(intent);
break;
}
}
});
}
@Override
public void onClick(View v) {
}
}
如果要以編程方式將數據設置為EditText
addtext.setText("Some text");
從捆綁中獲得標題后
title = bundle.getString("title");
將title
設置為EditText
addtext.setText(title)
以后的用戶可以根據需要進行更改
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.