在这里,我使用了可点击的URL Textview,它可以工作。但是,如何使用浏览器通过打开的URL设置可点击的并突出显示的文本。可以使用Android XML或kotlin,而无需使用Java代码setText(Html.fromHtml(""))。
String value = "<html>Visit Web <a href=\"http://www.domainname.com\">mysite</a> View</html>";
TextView text = (TextView) findViewById(R.id.text);
text.setText(Html.fromHtml(value));
text.setMovementMethod(LinkMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud) java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
Adapter.getView
at android.widget.AbsListView.obtainView(AbsListView.java:2346)
at android.widget.ListView.makeAndAddView(ListView.java:1876)
at android.widget.ListView.fillDown(ListView.java:702)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1671)
at android.widget.AbsListView.onLayout(AbsListView.java:2148)
Run Code Online (Sandbox Code Playgroud)
这是android的logcat.我尝试用java在适配器或其他方面工作正常的基本适配器.我尝试了public constructor和数组列表计数3发现我检查了它.总之它崩溃了getView
MyAdapter代码::
inner class MyAppAdapter constructor(private val parkingList: ArrayList<App>, private val mContext: Context) : BaseAdapter() {
override fun getCount(): Int {
return this.parkingList.size
}
override fun getItem(position: Int): Any {
return position
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View, parent: ViewGroup): View? { …Run Code Online (Sandbox Code Playgroud) 我想在gatter和setter模型的某些Variable类型上声明.
我可以在java中简单而干净的代码中声明吗?
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
Run Code Online (Sandbox Code Playgroud)
因为在将其转换为Kotlin时,它看起来像:
private var firstName: String? = null
fun getfirstName(): String {
return firstName
}
fun setfirstName(firstName: String) {
this.firstName = firstName
}
Run Code Online (Sandbox Code Playgroud)
什么是正确和最干净的方式?