0
    package com.example.ss.new_my_wid;

    import android.app.Activity;
    import android.app.PendingIntent;
    import android.appwidget.AppWidgetManager;
    import android.content.ComponentName;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RemoteViews;
    import android.widget.TextView;
    import android.widget.Toast;




    public class ItemChanging extends Activity implements View.OnClickListener, View.OnKeyListener
    {

        EditText EdT;
        Button btn_OK;
        Button btn_Cancel;
        Button btn_Delete;
        Intent intent;
        String str, changed_text;
        Toast tst;

        final static String CURRENT_TEXT_IN_ITEM = "current_text_in_item";
        final static String POSITION = "position";

        public ItemChanging() {
            super();
        }


        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.type_to_item);

            EdT = (EditText) findViewById(R.id.editText);
            intent = getIntent();
            str = intent.getStringExtra(CURRENT_TEXT_IN_ITEM);

            EdT.setText(str, TextView.BufferType.EDITABLE);

            btn_OK = (Button)findViewById(R.id.but_OK);
            btn_Cancel = (Button) findViewById(R.id.but_Cancel);
            btn_Delete = (Button) findViewById(R.id.but_Del);

            btn_OK.setOnClickListener(this);
            btn_Cancel.setOnClickListener(this);
            btn_Delete.setOnClickListener(this);
            EdT.setOnKeyListener(this);


        }


        @Override
        public void onClick(View v)
        {
            int pos = intent.getIntExtra(POSITION,0);
            switch (v.getId())
            {
                case R.id.but_OK:
                    changed_text = EdT.getText().toString();
                    MyFactory.data.set(pos, changed_text);
                    /*HERE need update of ListView*/

                    tst = Toast.makeText(this, changed_text, Toast.LENGTH_SHORT);
                    tst.show();
                    finish();
                    break;
                case R.id.but_Cancel:
                    finish();
                    break;
                case R.id.but_Del:
                    MyFactory.data.remove(pos);
                    MyFactory.data.add("");


                    finish();
                    break;
            }
        }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event)
    {
        return false;
    }
}

I have widget with ListView and activity with button. In activity I change an item in the ListView. When I click on the button changes are saved in ListView, but I dont know how to update the listView and the widget from activit.How can I do this?

P.S. sorry for my english =)

2 Answers2

3

Call notifyDataSetChanged() on your Adapter object once you've modified the data in that adapter.

How to refresh Android listview?

Community
  • 1
  • 1
StephenG
  • 2,851
  • 1
  • 16
  • 36
2

When ever you Made changes in your listview's data then you need to notify your adapter with new data

you can do it by calling notifyDataSetChanged(); method on your adaptor

for examlple

adapter.notifyDataSetChanged();
Jaykishan Sewak
  • 822
  • 6
  • 13