Skip to content Skip to sidebar Skip to footer

Android Listview Item Edit Operation

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 cou

Solution 1:

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

MainActivity.java

ListViewlist= (ListView) findViewById(R.id.yourlistview);
list.setOnItemClickListener(newAdapterView.onItemClickListener() {
   @OverridepublicvoidonItemClick(AdapterView<?> adapter, View view, int position, long id) {
      // use position to find your values// to go to ShowDetailsActivity, you have to use IntentIntentdetailScreen=newIntent(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.

Intenti= getIntent();
intposition= i.getIntExtra("position", 0);

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

Solution 2:

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

Post a Comment for "Android Listview Item Edit Operation"