0
視圖不會更新。我在哪裏可以添加notifydatasetchanged();我想,這是我需要這樣的列表視圖得到更新Android notifydatasetchanged不更新?
public class UninstallActivity extends Activity {
private AppAdapter mAppListAdapter = null;
private EditText mEditText = null;
private ListView mListView = null;
public void update() {
// TODO
mAppListAdapter.clear();
Intent aIntent = new Intent(Intent.ACTION_MAIN, null);
aIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager aPackageManager = getPackageManager();
List <ResolveInfo> aList = aPackageManager.queryIntentActivities(aIntent, PackageManager.GET_UNINSTALLED_PACKAGES);
for(ResolveInfo rInfo : aList) {
if (!isSystemPackage(rInfo))
mAppListAdapter.add(rInfo.activityInfo.applicationInfo);
System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(aPackageManager).toString());
}
if(mListView != null) {
mListView.setAdapter(mAppListAdapter);
}
}
private boolean isSystemPackage(ResolveInfo ri) {
return ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true : false;
}
public void remove(ApplicationInfo mApplicationInfo) {
Intent aIntent = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + mApplicationInfo.packageName));
startActivity(aIntent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mEditText = (EditText) findViewById(R.id.EditText);
mEditText.setSingleLine();
mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length() > 0) {
// TODO
mAppListAdapter.clear();
Intent aIntent = new Intent(Intent.ACTION_MAIN, null);
aIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager aPackageManager = getPackageManager();
List<ResolveInfo>aList = aPackageManager.queryIntentActivities(aIntent, PackageManager.GET_UNINSTALLED_PACKAGES);
for(ResolveInfo rInfo : aList) {
String aName = rInfo.activityInfo.applicationInfo.loadLabel(aPackageManager).toString().toLowerCase();
String aValue = s.toString().toLowerCase();
if (!isSystemPackage(rInfo))
if(aName.contains(aValue)) {
mAppListAdapter.add(rInfo.activityInfo.applicationInfo);
}
}
if(mListView != null) {
mListView.setAdapter(mAppListAdapter);
}
}
else {
UninstallActivity.this.update();
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
mListView = (ListView) findViewById(android.R.id.list);
mAppListAdapter = new AppAdapter(this);
this.update();
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ApplicationInfo mApplicationInfo = (ApplicationInfo) mAppListAdapter.getItem(position);
UninstallActivity.this.remove(mApplicationInfo);
}
});
}
}
這就是我想知道我在哪裏設置和調用notifydatasetchanged? – user818610