如何在发送之前验证在edittext中输入的USSD代码
在这里,我把一些代码请帮助我.
ussd_edittext.addTextChangedListener(new TextWatcher()
{
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
ussd_edittext.setError("Invalid password");
ussd_ok.setEnabled(false);
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (ussd_edittext.getText().toString().trim().replaceAll("[^0-9#*]", "").length() < 4) {
ussd_edittext.setError("USSD code must contain * and #");
ussd_ok.setEnabled(false);
}
}
public void afterTextChanged(Editable s) {
Character cr = s.toString().charAt(0);
if(s.length() < 1)
{
if(!( (cr == '*') ) )
{ ussd_edittext.setError("USSD code must contain * and #");
ussd_ok.setEnabled(false);
}
else {
ussd_ok.setEnabled(true);
} …Run Code Online (Sandbox Code Playgroud) 我在按钮点击时创建了警报管理器。但是手机重启后就不行了。我的 AlarmbroadcastReceiver 在手机重启时没有调用。它在电话锁定时工作,应用程序被杀死但在电话重启后不起作用我创建了一个进度条,它在按钮点击时启动并在警报广播触发后停止,但在手机重启时它不会停止。我已经添加了我的按钮点击事件和广播接收器类
按钮点击事件
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pb1.setVisibility(View.VISIBLE);
progress_edit.putBoolean("progress_one", true);
progress_edit.apply();
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intnt = new Intent(getApplicationContext(), AlarmbroadcastReceiver.class);
intnt.setAction("com.ex.Alarm");
PendingIntent pending = PendingIntent.getBroadcast(getApplicationContext(), 0, intnt, 0);
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 120000, pending);
Log.d("Broadcast ","Fired");
}
});
Run Code Online (Sandbox Code Playgroud)
广播接收器类
@Override
public void onReceive(Context context, Intent intent) {
Log.d("inside","broadcast receive");
if(intent.getAction().equalsIgnoreCase("com.ex.Alarm"))
{
enterSys_progress_edit.putBoolean("progress_one", false);
enterSys_progress_edit.apply();
Toast.makeText(context,"Receive",Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我的清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.krutarth.alarm">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action …Run Code Online (Sandbox Code Playgroud) 如何使 textview Clickable false ?我试过textView.setClickable(false)但它不起作用我在下面添加我的代码段。
t1 = (TextView)findViewById(R.id.text_View1);
t1.setClickable(false);
//t1.setFocusableInTouchMode(false);
//t1.setEnabled(false);
t1.setFocusable(false);
t1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1.setText("clicked");
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我点击 textview 时,文本会发生变化,请帮助我。
我遇到了一个问题,当我将数据添加到数组列表然后将其添加到适配器之后,当我将其设置为recycleler视图适配器时,它会自动跳转到顶部我如何能够阻止它,就像我想在虚拟空间中添加数据一样我也尝试过使用 -
runOnUiThread(new Runnable() {
public void run() {
innerAdapter.notifyDataSetChanged();
}
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我怎么解决呢?
添加一些代码以便向上滚动
if (isScrollUp) {
isEnable = true;
userChats.addAll(0, model.data);
innerChatAdapter.notifyDataSetChanged();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
nnerChatAdapter.notifyItemInserted(0);
recyclerView.smoothScrollToPosition(0);
}
}, 1);
}
Run Code Online (Sandbox Code Playgroud)