Question

I am inserting data into a Sqlitedatabase. I want those data to be displayed in a Listview in a fragment class. The problem is that my listview doesn't get loaded with the new data immediately. In other words it is not getting refreshed until I go to some other activity and come back. Can any one suggest me a solution. My codes are as follows:

public class SentTaskFragment extends Fragment {
 ArrayList<HashMap<String, String>>val=new ArrayList<HashMap<String,String>>(); 
public SentTaskFragment(){}
     public View onCreateView(LayoutInflater inflater1, ViewGroup container,Bundle savedInstanceState) {
        View rootView = inflater1.inflate(R.layout.listview_header_row, container, false);
        Databasehandler db=new Databasehandler(getActivity().getApplicationContext());
        final ListView l=(ListView) rootView.findViewById(R.id.listViewad);
        int count=db.getcounttask();
         Log.i("count task",""+count);
         if(count==0)
         {
        Toast.makeText(getActivity(), "No Task to Display", Toast.LENGTH_SHORT).show();
    }
        else
    {
            if(id.compareTo("empty")!=0)
            {
    val=db.getTaskSent(id);
    Toast.makeText(getActivity(), "arg2"+val, Toast.LENGTH_SHORT).show();
            }
   ListAdapter k=new SimpleAdapter(getActivity(),val,R.layout.r,new String[]{"TaskId","heading","status"},new int[]{R.id.textViews,R.id.textViews1,R.id.textstatus});

           l.setAdapter(k);
    }

No correct solution

OTHER TIPS

put this code after you insert data into your database

((BaseAdapter)l.getAdapter()).notifyDataSetChanged();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top