我有两个活动,我在下一个Activity中实现了更新查询,我希望在我的List-view中添加更新的行,该行位于Previous Activity中。我尝试更新数据库表行但列表视图没有更新。我怎么能解决这个问题。可以有人帮助我。
这是我在数据库助手类
中的Sq Lite中的填充列表视图public List<All_Post> getAllDescriptions()
{
List<All_Post> allPostDescList = new ArrayList<All_Post>();
String selectQuery = "select * from " + Table_AllPost_Table + " where ActiveStatus = '1' ORDER BY ActionDate DESC";
db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do
{
All_Post allPostDesc = new All_Post();
allPostDesc.setID(cursor.getInt(cursor.getColumnIndex("ALL_ACT_ID")));
allPostDesc.setStrActiveStatus(cursor.getString(cursor.getColumnIndex("ActiveStatus")));
allPostDesc.setStrActivityId(cursor.getString(cursor.getColumnIndex("ActivityId")));
allPostDesc.setStrRemark(cursor.getString(cursor.getColumnIndex("Remark")));
allPostDesc.setStringInspectorname(cursor.getString(cursor.getColumnIndex("inspectorName")));
allPostDesc.setStrNotationNo(cursor.getString(cursor.getColumnIndex("HashTag")));
allPostDesc.setStrShortName(cursor.getString(cursor.getColumnIndex("Type_ShortRGN")));
allPostDesc.setStrUserId(cursor.getString(cursor.getColumnIndex("UserId")));
allPostDesc.setStrvessel_Id(cursor.getString(cursor.getColumnIndex("VesselId")));
String strSqliteDate = cursor.getString(cursor.getColumnIndex("ActionDate"));
DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
Date parsed = null;
try
{
parsed = outputFormat.parse(strSqliteDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String outputText = outputFormat.format(parsed);
allPostDesc.setActiondate(outputText);
allPostDescList.add(allPostDesc);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return allPostDescList;
}
这是我来自Sq Lite的填充列表视图
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_post);
ctx = this;
dbhelper = new MyDbHelper(this);
dbhelper.onOpen(db);
imgLeftmenu = (ImageView) findViewById(R.id.imgLeftMenu);
imgSearch = (ImageView) findViewById(R.id.imgSearch);
imgAdd = (ImageView) findViewById(R.id.imgAdd);
listView = (ListView) findViewById(R.id.listview_AllPost);
Log.e(" After "," Filter Screen !!! ");
populateList();
}
@Override
protected void onResume() {
super.onResume();
populateList();
}
private void populateList() {
descArray.clear();
List<All_Post> allDesc = dbhelper.getAllDescriptions();
for (All_Post all_Post : allDesc)
{
String strInspectorname = all_Post.getStringInspectorname();
Log.e("strInspectorname "," = " + strInspectorname);
descArray.add(all_Post);
}
if (adapter == null)
{
Log.e("Adapter ", " == Null !!!! ");
adapter = new MyListAdapter(this, R.layout.all_post_row, descArray);
listView.setAdapter(adapter);
}
else if (adapter != null)
{
Log.e("Adapter ", " != Null !!!! ");
adapter.notifyDataSetChanged();
adapter = new MyListAdapter(this, R.layout.all_post_row, descArray);
listView.setFastScrollEnabled(true);
listView.setAdapter(adapter);
}
}
这是我在onCreate()
中的另一个下一个活动代码 public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.filter_screen);
ctx = this;
Log.e("I m", " in Filter !!!");
dbhelper = new MyDbHelper(this);
dbhelper.onOpen(db);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
str_Authentication_Token = sharedPreferences.getString("strAuthentication_Token", "");
str_UserId = sharedPreferences.getString("strUserId", "");
str_UserName = sharedPreferences.getString("strUserName", "");
imgProfilePic = (ImageView) findViewById(R.id.img_ProfilePic);
imgBtn_LogOut = (ImageView) findViewById(R.id.img_LogOut);
listView_Filter = (ListView) findViewById(R.id.filter_List);
txtUserName = (TextView) findViewById(R.id.txt_Username);
txtUserName.setText(str_UserName);
userAutoComplete_TextView = (AutoCompleteTextView) findViewById(R.id.autoComplete_UserList);
db = dbhelper.getWritableDatabase();
String query = "select * from Inspector";
Cursor cursor = db.rawQuery(query, null);
if (cursor.moveToFirst()) {
do {
Filter filter = new Filter();
filter.setName(cursor.getString(cursor.getColumnIndex("Inspector_name")));
String strActiveStatus = cursor.getString(cursor.getColumnIndex("ActiveStatus"));
String strInspectorname = cursor.getString(cursor.getColumnIndex("Inspector_name"));
if (strActiveStatus.equals("1")) {
userlist.add(strInspectorname);
Log.e("strInspectorname", " from Inspector = " + strInspectorname + " & strActiveStatus = " + strActiveStatus);
}
} while (cursor.moveToNext());
}
cursor.close();
db.close();
userAutoComplete_TextView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, userlist));
userAutoComplete_TextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String foundItem = arg0.getItemAtPosition(arg2).toString();
Log.e("You have selected --->", "" + foundItem);
Filter filter = new Filter();
filter.setName(foundItem);
filter_ArrayList.add(filter);
filterAdapter = new FilterAdapter(Filter_Screen.this, R.layout.filter_list_item, filter_ArrayList);
listView_Filter.setAdapter(filterAdapter);
db = dbhelper.getWritableDatabase();
db.execSQL("UPDATE ALL_Post SET ActiveStatus ='1' WHERE inspectorName ='" + foundItem + "'");
Log.e("Updated ListView --->", "" + foundItem);
}
});
}
先谢谢了。
答案 0 :(得分:1)
尝试使用adapter.notifyDataSetChanged();在onResume的第一个Activity中。