Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to refresh the linear layout view after deleting an element
    text
    copied!<p>I have a simple app, in one activity I take name and date of birth. I store it in the database. and in the main activity I have linearlayout which will show all the names.</p> <p>When I click on any of the name in the main activity, it should delete that name from the database and also refresh the view. </p> <p>I am able to delete the entry from database, but my linear layout view is not being updated. Can some one pls help.</p> <p>public class child extends Activity { private Intent intent; private LinearLayout layout; private LayoutInflater linflater; private int i =0; private Cursor cr;</p> <pre><code>/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.child); layout = (LinearLayout)findViewById(R.id.layout); Button addBtn = (Button)findViewById(R.id.AddButton); Button remBtn = (Button)findViewById(R.id.RemoveButton); intent = new Intent(this,login.class); layout = (LinearLayout) findViewById(R.id.mylayout1); linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); //Check the database if there are any entries available. If available, then //list them on the main screen final myDBAdapter mydb = new myDBAdapter(getApplicationContext()); mydb.open(); cr = mydb.GetMyData(); if(cr.getCount()&gt;0) { cr.moveToFirst(); for (int i=0;i&lt;cr.getCount();i++) { cr.moveToPosition(i); buildList(cr.getString(1),cr.getString(2)); } } //Start the login activity which will return the newly added baby name addBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivityForResult(intent, 1001); } }); //Remove all the entries from Database remBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(cr.getCount()&gt;0) { cr.moveToFirst(); for (int i=0;i&lt;cr.getCount();i++) { Toast.makeText(getApplicationContext(), cr.getString(1), Toast.LENGTH_LONG).show(); mydb.RemoveEntry(cr.getString(1)); cr.moveToPosition(i); } } } }); mydb.close(); } private void buildList(final String bname,String bsex) { final View customView = linflater.inflate(R.layout.child_view, null); TextView tv = (TextView) customView.findViewById(R.id.TextView01); //tv.setId(i); tv.setText(bname); tv.setTextColor(getResources().getColor(R.color.black)); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myDBAdapter mydb = new myDBAdapter(getApplicationContext()); mydb.open(); if (mydb.RemoveEntry(bname)&gt;0) { Toast.makeText(getApplicationContext(), "Row deleted", Toast.LENGTH_LONG).show(); </code></pre> <p>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// WHAT IS REQUIRED HERE TO UPDATE THE VIEW??? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</p> <pre><code> } else { Toast.makeText(getApplicationContext(), "Row not deleted", Toast.LENGTH_LONG).show(); } } }); layout.addView(customView); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ if(requestCode == 1001) { if(resultCode == RESULT_OK) { Bundle extras = data.getExtras(); buildList(extras.getString("bname"),extras.getString("bsex")); } } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload