public void getIntentProcess(Intent intent) {
String comment = intent.getStringExtra("comment");
int rating = Math.round(intent.getFloatExtra("rating", 0.0f));
if (comment != null) {
items.add(new CommentItems("kim78**", rating, comment, R.drawable.user1));
adapter.notifyDataSetChanged();
}
}
Even if you receive an intro from one activity and add it to the list view, only one is added. I hope it will be added several times
android intent
When calling startActivity()
, Activity is newly called, so to implement the desired function, use startActivityForResult()
when calling CommentWriterView
and update the setResult()
list again.
I'm not in a situation to write an example code, so try it and if you don't understand it well, I'll let you know in detail.
public class CommentWriteView extends AppCompatActivity {
EditText commentText;
RatingBar ratingBar;
Button saveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comment_write_view);
commentText = findViewById(R.id.editText_comment);
ratingBar = findViewById(R.id.write_ratingbar);
saveButton = findViewById(R.id.saveButton);
Button exitButton = findViewById(R.id.exitButton);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
String comment = commentText.getText().toString();
float rating = ratingBar.getRating();
intent.putExtra("comment", comment);
intent.putExtra("rating", rating);
startActivity(intent);
returnToMain();
}
});
exitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
public void returnToMain() {
String comment = commentText.getText().toString();
float rating = ratingBar.getRating();
Intent intent = getIntent();
intent.putExtra("comment", comment);
intent.putExtra("rating", rating);
setResult(RESULT_OK, intent);
finish();
}
}
© 2024 OneMinuteCode. All rights reserved.