我想首先让数据显示在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) {
}
}
答案 0 :(得分:0)
如果要以编程方式将数据设置为EditText
addtext.setText("Some text");
答案 1 :(得分:0)
title = bundle.getString("title");
将title
设为EditText
addtext.setText(title)
以后用户可以根据需要进行更改