开发应用程序以获取安装的APPS列表,其中两个按钮是启用密码,其他是更改密码,如果应用程序未锁定,则更改密码按钮将被隐藏,当我单击按钮时我无法获取密码选项,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btOnOff = (Button) findViewById(R.id.bt_on_off);
btOnOff.setText(R.string.enable_passcode);
btOnOff.setOnClickListener(this);
btChange = (Button) findViewById(R.id.bt_change);
btChange.setText(R.string.change_passcode);
btChange.setOnClickListener(this);
update();
packageManager = getPackageManager();
List<PackageInfo> packageList = packageManager
.getInstalledPackages(PackageManager.GET_PERMISSIONS);
List<PackageInfo> packageList1 = new ArrayList<PackageInfo>();
}
apkList = (ListView) findViewById(R.id.applist);
apkList.setAdapter(new ApkAdapter(this, packageList1, packageManager));
}
@Override
public void onClick(View view) {
if (view.equals(btOnOff)) {
int type = LockManager.getInstance().getAppLock().isPasscodeSet() ? AppLock.DISABLE_PASSLOCK
: AppLock.ENABLE_PASSLOCK;
Intent intent = new Intent(this, AppLockActivity.class);
intent.putExtra(AppLock.TYPE, type);
startActivityForResult(intent, type);
} else if (view.equals(btChange)) {
Intent intent = new Intent(this, AppLockActivity.class);
intent.putExtra(AppLock.TYPE, AppLock.CHANGE_PASSWORD);
intent.putExtra(AppLock.MESSAGE,
getString(R.string.enter_old_passcode));
startActivityForResult(intent, AppLock.CHANGE_PASSWORD);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case AppLock.DISABLE_PASSLOCK:
break;
case AppLock.ENABLE_PASSLOCK:
case AppLock.CHANGE_PASSWORD:
if (resultCode == RESULT_OK) {
Toast.makeText(this, getString(R.string.setup_passcode),
Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
updateUI();
}
private void updateUI() {
if (LockManager.getInstance().getAppLock().isPasscodeSet()) {
btOnOff.setText(R.string.disable_passcode);
btChange.setEnabled(true);
} else {
btOnOff.setText(R.string.enable_passcode);
btChange.setEnabled(false);
}
}
} 以什么方式我必须为两个按钮设置clicklistener?
这是错误
我无法开始活动。如果这是错误的,请以不同的方式建议我