1

In my app I have tab menu : Add tab,View tab.

in Add tab: I add data to database in View tab: I select data from database into listview

now I have problem: when I add a data from add tab and switch into viewtab I can't view last adding into database, but if I close app and open it new time, i can get last adding

any idea about solve of this problem please

Code :

`view tab code:

public class ViewEvents extends Activity {

DBAdapter DB=new DBAdapter(this);

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewevents);

    final ListView myListView = (ListView)findViewById(R.id.MyList);

    //  final EditText myEditText = (EditText)findViewById(R.id.myEditText);

      // Create the array list of to do items
      final ArrayList<String> todoItems = new ArrayList<String>();
      final ArrayAdapter<String>  aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, todoItems);

       DB.open();
     Cursor c=DB.select();
      c.moveToFirst();
      Integer n=new Integer(c.getCount());

    for(int i=0;i<c.getCount();i++)
    {
         todoItems.add(0, c.getString(0));
         c.moveToNext();
    }


       // todoItems.add(0, c.getString(0));
        aa.notifyDataSetChanged();
        myListView.setAdapter(aa);








}

}

add tab code:

public View getView(int position, View convertView, ViewGroup parent) {

        ButtonHolder holder2;
        if (convertView == null) {

            holder2 = new ButtonHolder();       


            convertView = mInflater.inflate(R.layout.item, null);

            holder2.caption = (Button) convertView.findViewById(R.id.Bte);

            convertView.setTag(holder2);


        } else {

            holder2 = (ButtonHolder) convertView.getTag();

        }


        holder2.caption.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub


                TextView names = holderpartner.caption;
                TextView date = holderdv.caption;
                TextView time = holderviewmtime.caption;
                String address = "sdfgkhj";

                event e=new event( names.getText().toString(), address,date.getText().toString(), new java.sql.Time(9, 30, 30));


                DB.open();
                DB.insertTask(e);


                date.setText("");
                time.setText("");

                Toast.makeText(getBaseContext(), "Done",Toast.LENGTH_LONG).show();

            }
        });`
SWE
  • 131
  • 2
  • 7
  • 20
  • are you notifying the URI of changes? are you calling setNotificationUri on the cursor when you query? It's hard to tell without seeing your code – dymmeh May 16 '12 at 15:02

1 Answers1

1

Add addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); flag to your intent in your TabHostActivity, so everytime you select your tab it's content gets refreshed. Do something similar to this :

intent = new Intent().setClass(this, Notices.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        spec = tabHost.newTabSpec("notices").setIndicator(getString(R.string.notices),
                res.getDrawable(R.drawable.ic_tab_notices))
            .setContent(intent);
        tabHost.addTab(spec);

In my situation it's working.

Android-Droid
  • 14,365
  • 41
  • 114
  • 185