Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh List From Another Activity

I have 3 activities and 1 class;

MobilEpostaActivity (Main Activity) gives the datas from the Gmail server intent these datas to ListeleActivity (Fill and show the ListView) and ListeleActivity fills these datas to the ListView and when item onClick on ListView the item's click datas is intent to the GoruntuleActivity (Show the onclick item's information). And also I have a class "Baglantı" (means Connection) and it has all other methods which are necessary for each.

My problem is in here: when the user click on to the "Delete" button. I want to refresh the listview and show the next mail to the user. when user clicks to the delete button, I can show the user next mail with add 1 to the position and show it. But it is not work properly, because of its attachments are complicated.

Now starting with the MobilEpostaActivity; I am taking the username and password from the user and pass them to Baglantı class for connection to the server. Then I am gettin the result body, from, subject in arraylists. Then I pass these body, from and subject to the ListeleActivity with intent.

public void epostaListeleme() throws MessagingException, IOException 
    {
        final Intent intent = new Intent(this, ListeleActivity.class);
        intent.putStringArrayListExtra(bodylistesi ,(ArrayList<String>) getBodyList());
        intent.putStringArrayListExtra(konulistesi ,(ArrayList<String>) getKonuList());
        intent.putStringArrayListExtra(kimdenlistesi ,(ArrayList<String>) getKimdenList());
        startActivity(intent);
        }

In the ListeleActivity():

Getting the datas from the MobilEpostaActivity with Bundle. Filling the listview with "from" data. And waiting for listItemOnClick. If Onclick Action is happen then pass the datas to the GoruntuleActivity.**

In the GoruntuleActivity():

Getting the datas from the ListeleActivity with Bundle. And (Here is the important part) waiting for the Delete Button OnClick. If On Onclick Action is happen FIRST) delete the position from the ListView.

arrayAdapter.remove(arrayAdapter.getItem(position));
listBaglanti.RefreshedPositions(position);
arrayAdapter.notifyDataSetChanged();

SECOND) Delete the position's datas from the bodylist , fromlist and subjectlist:

public void RefreshedPositions(int position) 
{
    list.remove(list.get(position));
    kimdenlist.remove(kimdenlist.get(position));
    konulist.remove(konulist.get(position));
}

THIRD) Hold these "changed" lists in arraylists:

bodylistRefresh = baglan.list;
kimdenlisteRefresh = baglan.kimdenlist;
konulisteRefresh = baglan.konulist; 

FOURTH) Set these "changed" lists to the MobilEpostaActivity's intent (the one of ListeleAcitivity's):

MobilEpostaActivity mobilObject = new MobilEpostaActivity();
mobilObject.setKonuList(konulisteRefresh);
mobilObject.setKimdenList(kimdenlisteRefresh);
mobilObject.setBodyList(bodylistRefresh);

As you think the process should start over again. But it doesn't start because with the Fourth step, I don't think so I made a refresh for the ListView.

Maybe I went a way which one is hard. But I hope, you tell me the right thing for refresh the listview and show the next mails. Also my screenshots;

When I first open the application : There is 3 mails from Merve. Positions : 0,1,2*

enter image description here

After Click the Delete Button : The ListView is refresh and the position=1's item is deleted. But it is not deleted on GoruntuleActivity's Screen.

enter image description here

like image 212
Merve Avatar asked Aug 08 '26 00:08

Merve


1 Answers

It looks like you have too many lists involved. I think that you should be able to just remove the item from the main list like so:

arrayAdapter.remove(position);
listBaglanti.RefreshedPositions(position);
arrayAdapter.notifyDataSetChanged();

public void RefreshedPositions(int position) 
{
    list.remove(position);
    kimdenlist.remove(position);
    konulist.remove(position);
}

Just pass in the position as an int value instead of retrieving and then removing the object.

like image 77
user922295 Avatar answered Aug 10 '26 13:08

user922295



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!