我正在尝试进行过滤查询:
public Cursor runQuery(CharSequence constraint) {
return getActivity().getContentResolver().query(
Phone.CONTENT_URI,
new String[] {Phone.DISPLAY_NAME, Phone.NUMBER, Phone.TYPE, Phone._ID },
Phone.DISPLAY_NAME + " LIKE '" + constraint + "%'",// <-- problem here
null,
Phone.DISPLAY_NAME);
}
Run Code Online (Sandbox Code Playgroud)
但LIKE运算符对于非ascii字符以区分大小写的方式工作(如SQLite文档所述).有没有办法让案例不敏感的LIKE?(ps我测试俄罗斯符号)
不起作用的事情:
需要帮助或建议.谢谢.
我对Java lambdas和方法引用行为有点困惑.例如,我们有这个代码:
import java.util.function.Consumer;
public class Main {
private static StringBuilder sBuilder = new StringBuilder("1");
public static void main(String[] args) {
Consumer<String> consumer = s -> sBuilder.append(s);
sBuilder = new StringBuilder("2");
consumer.accept("3");
System.out.println(sBuilder);
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
23
Run Code Online (Sandbox Code Playgroud)
这可以按预期工作,但如果我们更换
s - > sBuilder.append(s)
同
sBuilder ::追加
输出将是:
2
Run Code Online (Sandbox Code Playgroud)
你有任何想法如何解释这个?这不是一回事吗?谢谢.
我的布局中有一个 TextView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="Hello"
/>
Run Code Online (Sandbox Code Playgroud)
textAllCaps 效果很好,没问题。但是当我尝试通过添加 textIsSelectable 使文本可选时
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textIsSelectable="true"
android:text="Hello"
/>
Run Code Online (Sandbox Code Playgroud)
textAllCaps 不起作用。似乎这两个属性不能正常工作。您有什么建议为什么会发生这种情况以及如何使文本全部大写和可选择(我对最清晰的方式感兴趣,而不是手动设置文本更改侦听器和大写文本)。我将不胜感激任何建议,谢谢。
我喜欢 MVP 的概念,它对我组织代码有很大帮助,但是每次当我需要从外部应用程序、对话框或请求权限获取结果时,我都会遇到同样的问题 -架构的哪个组件应该关心这个?
例如,我们需要实现以下行为:
所以,我们可以这样做(也决定 Fragment 实现 View,包含到 Presenter 的链接并向它发送 UI 事件):
interface View {
void showRecognizer();//2
void showChooseDialog(List<String> items);//4
}
interface Presenter {
void onButtonClick();//1
void onRecognizerResult(List<String> results);//3
void onResultChosen(String result);//5
}
Run Code Online (Sandbox Code Playgroud)
好的,它会工作,但我们有一些问题:
所以,我想知道您对此的看法,如何做得更好(或者您认为这没问题)?
一般而言:启动对话和活动,请求权限,处理结果,从 MVP 和干净架构的角度来看,这是谁的职责?
鼓励任何想法或建议。请帮我澄清一下,谢谢。
当我将url加载到WebView并尝试打开链接时,其中一些显示错误页面,如:
net :: ERR_UNKNOWN_URL_SCHEME意图://maps.yandex.ru?utm_medium = tab ...
如何打开此链接,或者至少检查是否安装了适当的应用并运行它?
我试图通过实现自定义WebViewClient来覆盖url加载:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.startsWith("http")) {
getActivity().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)));
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,应用程序崩溃与ActivityNotFoundException.
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=intent://maps.yandex.ru?utm_medium=tab-maps&text=???????&utm_source=serp&yandexuid=2258091361456330110 }
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at android.app.Activity.startActivityForResult(Activity.java:3930)
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at android.app.Activity.startActivityForResult(Activity.java:3890)
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at android.app.Activity.startActivity(Activity.java:4213) …Run Code Online (Sandbox Code Playgroud) 我有保存片段状态的问题.我尝试使用setRetainInstance,但无法使其工作(((我使用button1将状态更改为2,但在更改屏幕方向后,按下按钮2时看到1.我的错误在哪里?
public class TestFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
setRetainInstance(true);
super.onCreate(savedInstanceState);
}
private String state = "1";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout, container, false);
//button for changing state
((Button)view.findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
state = "2";
}
});
//button for showing state
((Button)view.findViewById(R.id.button2)).setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(getActivity(), state, Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
活动:
public class MainActivity …Run Code Online (Sandbox Code Playgroud)