0

I am new at developing Android App.I have a MainActivity that has a ListView.The data on Listview is hold in a Arraylist.(I dont have any DB).Listview items has 4 field such as coursecode,coursetitle,courselevel,coursedescription.When I clicked an item on Listview,a new activity(ShowDetailActivity) will be launced in order to view detail of course.The editable of the EditViews on ShowDetailActivity are false.On ShowDetailActivity I have an option menu item (Edit).When I clicked the Edit option menu item,a new activity(EditCourseDetailActivity) will be launched and the the user will be edit details of course.

Edited detail of the specific course on EditCourseDetailActivity must be transfer to ShowDetailActivity and then to MainActivity

I dont know I could explain?

How can I handle this situation please help me !!!! Thanks for your comment in advanced

MainActivity ---> ShowDetailActivity ---> EditCourseDetailActivity ---- | | MainActivity <----ShowDetailActivity <---------------------------------

MUMBUÇOĞLU
  • 251
  • 1
  • 8
  • 24

2 Answers2

1

For ListView (MainActivity), you can do setOnItemClickListener. For example:

MainActivity.java

ListView list = (ListView) findViewById(R.id.yourlistview);
list.setOnItemClickListener(new AdapterView.onItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
      // use position to find your values
      // to go to ShowDetailsActivity, you have to use Intent
      Intent detailScreen = new Intent(getApplicationContext(), ShowDetailActivity.class);
      detailScreen.putExtra("position", position); // pass value if needed
      detailScreen.putExtra("para2", para2);
      startActivity(detailScreen);
   } 
});

DetailScreen.java

This is how you receive from MainActivity.

Intent i = getIntent();
int position = i.getIntExtra("position", 0);

Then when Edit button is clicked, use the intent to go to next activity (EditCourseDetails).

4tee
  • 86
  • 4
  • where can I hold position information? I use dynamic fragment and I have CourseDataFragment.java.I can get the position information in onActivityCreated method on CourseDataFragment.java.How can I use the information.ShowCourseActivity and EditCourseActivity(both) use CourseDataFragment.java – MUMBUÇOĞLU Dec 02 '14 at 23:01
  • In addition, how can I pass the position info from EditCourseActivity class to MainActivity class.In order to make it I used an interface which is implemented by MainActivity.On EditCourseActivity I created interface reference like MyInterface interface=(MyInterface)MainActivity.class interface.updateValue(position) .But it didnt work – MUMBUÇOĞLU Dec 03 '14 at 06:47
  • I am not sure what CourseDataFragment.java is about. Basically, position tells you the item position that you have clicked on ListView. Based on position value, you can retrieve your item details from your ArrayList. You can continue to pass the position value from ShowDetailsActivity to EditCourseDetailActivity using the same Intent method. So, when you edit the value, it should change on your ArrayList, therefore, when you are back at MainActivity, your ListView will display the new values. – 4tee Dec 04 '14 at 02:03
  • this is what I want.Great –  Feb 05 '20 at 06:57
0

Look at this topic. It is similar to your situation.

In you case, the idea is to send the data throught the Intent to your different activities. The modified data will be send back to the activity by the same process.

I believe that your object in the ArrayList must be Serializable.

You will find explainations in these links:

P.S.: Use the startActivityForResult and onActivityResult to get the Intent as explained by tiago7

Community
  • 1
  • 1
Nogebour
  • 141
  • 7