How to modify the listview content in this situation in android?

user782104

I am working on a alarm application. The structure is somehow complex. It works like that:

The main activity is a FragmentTabhost activity, it has 4 tabs, one of the fragment is the alarm list.

So, the alarm is trigger by alarmManager, it first call the boardcast receiver , in the receiver there is a service , that start a new activity, showing the detail info. of the alarm.

And that is it. What I would like to do is when the user onbackpress that new activity, I would like to update the alarm list in that fragment. How to achieve that? Thanks for helping

Update : Attempt use Boardcast receiver but it does not receive

in the Alarm Activity

@Override
    public void onBackPressed() {
        Log.d("test1","test R1");
        Intent intent = new Intent("on_alarm_remove");
        LocalBroadcastManager.getInstance(ctx).sendBroadcast(intent);
        super.onBackPressed();
    }

in the Alarm tab Fragment

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        ctx = getActivity();

        intentFilter = new IntentFilter("on_alarm_remove");
        LocalBroadcastManager.getInstance(ctx).registerReceiver(mMessageReceiver, intentFilter);
}

private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("test1","test R");
            db.removeRecord(db.getFirstAlarm().alarm_id);
            reloadFragment();
        }
    };

    @Override
    public void onPause() {
        if (mMessageReceiver != null)
            LocalBroadcastManager.getInstance(ctx).unregisterReceiver(mMessageReceiver);
        super.onPause();
    }

In manifest

<receiver android:name=".reminder.ReminderFrag$mMessageReceiver" />

It doesn't crash, but nothing happen, In the log "test R1" has run but "test R" does not. Thanks again for helping

eddie

Assuming this only needed if the fragment is present, then you can get the fragment by id in the activity:

public void onBackPressed() {
  Fragment f = getFragmentManager().findFragmentById( ... ); // Fragment's Id 
  if (f.getClass() == AlarmFragment.class) {
     ((AlarmFragment)f).removeRecord();
     return;
  }
  super.onBackPressed();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to display html content in listview in android?

From Dev

android how to build listview into drawer fragment content?

From Dev

How to modify file content?

From Dev

Android ListView not showing content

From Dev

Aligning Content in an Android ListView

From Dev

How to modify existing <content> in a element?

From Dev

RegEx: How to modify the content of a group

From Dev

Where and how to modify transcluded content?

From Dev

How to Modify Content in a Text Block

From Dev

Where and how to modify transcluded content?

From Dev

How to Modify Content in a Text Block

From Dev

Android Share Content OnClick Listview

From Dev

Android Content Box - custom listview

From Dev

how to overcome from this situation of tabwidget in android

From Dev

How to solve this situation about ffmpeg with Android NDK

From Dev

how to overcome from this situation of tabwidget in android

From Dev

MvvmCross DataBinding To Modify Individual Item in Android ListView

From Dev

How to clear ListView, it just adds new content after old content in Android App?

From Dev

How to modify only one row at a time in Listview?

From Dev

How to modify only one row at a time in Listview?

From Dev

How to modify row content in angular js?

From Dev

How do I modify the node content with Nokogiri?

From Dev

How to modify HTML content based on angular controller

From Dev

How to modify the content of WebRTC MediaStream video track?

From Dev

How to modify Content-Type in postman

From Dev

How to modify Content-Type in postman

From Dev

Inno Setup Compiler: How to modify file content

From Dev

How do I modify the content of an HttpEntity

From Dev

Android LinearLayout weight and wrap_content of ListView

Related Related

HotTag

Archive