I got problem in delete function there.When I click on delete, it works and delete the record in sqlite. But the problem is after it delete, it jump back to previous activity that using listview. But the deleted records still appear at there. I need to go out from the listview activity and go back again it just disappear. How should I do?
Here my delete function in database
public Integer deleteData (String property)
{
SQLiteDatabase db = this.getReadableDatabase();
return db.delete(houseContract.houseEntry.table2_name,"Property = ?",new String[] {property});
}
Here is my delete button works at the activity
public class SellerHouseDetail extends AppCompatActivity {
EditText etAddress,etDetail,etShowID;
TextView txType,txProperty,txPrice,txState,txTitle,txOther,txSize,txFullname;
Button bDelete;
String type,property,price,state,address,title,other,size,detail,fullname;
HousesDB db = new HousesDB(this);
Houses houses;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seller_house_detail);
txType = (TextView) findViewById(R.id.txTypes);
txProperty = (TextView) findViewById(R.id.txProperty);
txPrice = (TextView) findViewById(R.id.txPrice);
txState = (TextView) findViewById(R.id.txState);
etAddress = (EditText) findViewById(R.id.etAddress);
txTitle = (TextView) findViewById(R.id.txTitle);
txOther = (TextView) findViewById(R.id.txOther);
txSize = (TextView) findViewById(R.id.txSize);
txFullname = (TextView) findViewById(R.id.txFullname);
etDetail = (EditText) findViewById(R.id.etDetail);
etShowID = (EditText) findViewById(R.id.etShowID);
bDelete = (Button) findViewById(R.id.bDelete);
fullname = txFullname.getText().toString();
type = txType.getText().toString();
property = txProperty.getText().toString();
price = txPrice.getText().toString();
state = txState.getText().toString();
address = etAddress.getText().toString();
title = txTitle.getText().toString();
other = txOther.getText().toString();
size = txSize.getText().toString();
detail = etDetail.getText().toString();
Intent i = getIntent();
property = i.getStringExtra("house_property");
}
public void onResume()
{
super.onResume();
txProperty.setText(property);
houses = db.getInfo(property);
txType.setText(houses.getTypes());
txFullname.setText(houses.getFullname());
txPrice.setText(houses.getPrice());
txState.setText(houses.getState());
etAddress.setText(houses.getAddress());
txTitle.setText(houses.getTitle());
txOther.setText(houses.getOther());
txSize.setText(houses.getSize());
etDetail.setText(houses.getDetail());
DeleteData();
}
public void DeleteData() {
bDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(SellerHouseDetail.this);
dialog.setTitle("Delete Record");
dialog.setContentView(R.layout.activity_delete_layout);
dialog.show();
Button bYes = (Button) dialog.findViewById(R.id.bYes);
Button bNo = (Button) dialog.findViewById(R.id.bNo);
bYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer deletedRows = db.deleteData(txProperty.getText().toString());
if(deletedRows > 0)
{
Toast.makeText(SellerHouseDetail.this,"House Deleted",Toast.LENGTH_LONG).show();
finish();
}
else
{
Toast.makeText(SellerHouseDetail.this,"House not Deleted",Toast.LENGTH_LONG).show();
}
}
});
bNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
}
});
}
}
here is my listview activity that had problem
public class SellerHouses extends ListActivity {
TextView house_property;
String fullname;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seller_houses);
Intent i = getIntent();
fullname = i.getStringExtra("fullname");
}
public void onResume()
{
super.onResume();
HousesDB list = new HousesDB(this);
// list.insertProduct();
ArrayList<HashMap<String, String>> houseList = list.getSellerHouseList(fullname);
if(houseList.size()!=0) {
ListView lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
house_property = (TextView) view.findViewById(R.id.shouse_property);
String houseproperty = house_property.getText().toString();
//Go to House Detail
Intent objIndent = new Intent(getApplicationContext(),SellerHouseDetail.class);
objIndent.putExtra("house_property",houseproperty);
startActivity(objIndent);
}
});
ListAdapter adapter = new SimpleAdapter( SellerHouses.this,houseList, R.layout.activity_seller_house_info, new String[] { "id","property","type","state"}, new int[] {R.id.shouse_Id, R.id.shouse_property, R.id.shouse_type, R.id.shouse_state});
setListAdapter(adapter);
}else{
Toast.makeText(this, "No Houses is found!", Toast.LENGTH_SHORT).show();
}
}
}
Aucun commentaire:
Enregistrer un commentaire