private void populateList() { timeArrayList.clear(); timeArrayList.addAll(mDb.readTimingOfPackage(packageName)); timeListAdapter = new TimeListAdapter(this, timeArrayList); listView.setAdapter(timeListAdapter); timeListAdapter.notifyDataSetChanged(); }
@Override public boolean onContextItemSelected(MenuItem item) { // Toast.makeText(ShowTimeActivity.this,"hi"+deletePosition,Toast.LENGTH_SHORT).show(); int rowid = Integer.parseInt(timeArrayList.get(deletePosition).getTime_Id()); mDb.deleteTime(rowid); populateList(); return super.onContextItemSelected(item); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sharedPreferences = getSharedPreferences("pckName", MODE_PRIVATE); packageName = sharedPreferences.getString("packageName", null); listView = (ListView) findViewById(R.id.listview1); getActionBar().setTitle(packageName); Log.e("title", "" + getActionBar().getTitle()); position = sharedPreferences.getInt("position", -1); mDb = new MydatabaseHelper(this); mDb.open(); registerForContextMenu(listView); populateList(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_data_limit); sharedPreferences = getSharedPreferences("pckName", MODE_PRIVATE); packageName = sharedPreferences.getString("packageName", null); Log.e("p", "" + packageName); getActionBar().setTitle(packageName); mDb = new MydatabaseHelper(this); mDb.open(); btnSubmitdata = (Button) findViewById(R.id.btnDataLimit); datausage = (EditText) findViewById(R.id.edtdatalimit); List<String> list = new ArrayList<String>(); PackageManager pm = getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { try { PackageInfo info = getPackageManager() .getPackageInfo(packageInfo.packageName, PackageManager.GET_PERMISSIONS); if (info.requestedPermissions != null) { for (String p : info.requestedPermissions) { if (p.equals("android.permission.INTERNET")) { pm.getApplicationLabel(packageInfo).toString(); list.add( pm.getApplicationLabel(packageInfo) .toString()); // add in 2nd list if it is user installed app } } } } catch (Exception e) { e.printStackTrace(); } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); spinner = (Spinner) findViewById(R.id.planets_spinner); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { appName = spinner.getSelectedItem().toString(); Toast.makeText(AddDataLimitActivity.this, "" + appName, Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); btnSubmitdata.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { int data = Integer.parseInt(datausage.getText().toString()); if (data != 0 && appName != null) { DataUsage dataUsage = new DataUsage(); dataUsage.setPackageName(appName); dataUsage.setDatalimit(data); long id = mDb.addDataLimit(dataUsage); Log.e("d", "" + id); } else { Toast.makeText( AddDataLimitActivity.this, "Please enter valid data", Toast.LENGTH_SHORT) .show(); } } }); }