我需要为我正在开发的应用程序选项卡.所以我最终得到了tablayout,它包含很少的标签.代码如下:
private void setupNavTab() {
int[][] states = new int[][]{
new int[]{android.R.attr.state_selected},
new int[]{-android.R.attr.state_selected},
new int[]{-android.R.attr.state_enabled}
};
int[] colors = new int[]{
ContextCompat.getColor(getActivity(), R.color.cricut_selected_green),
ContextCompat.getColor(getActivity(), R.color.nav_bar_unselected_content),
ContextCompat.getColor(getActivity(), R.color.edit_button_text_color_inactive)
};
ColorStateList cslist = new ColorStateList(states, colors);
if (tabs != null) {
tabs.removeAllTabs();
tabs.setTabTextColors(cslist);
firstTab = tabs.newTab().setTag(TAB_FIRST);
View customFirstTabView = LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
firstTabView = (TextView) customFirstTabView.findViewById(R.id.textContainer);
firstTabView.setText(R.string.first);
firstTabView.setTextColor(cslist);
firstTab.setCustomView(customFirstTabView);
secondTab = tabs.newTab().setTag(TAB_SECOND);
View customSecondView = LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
secondTabView = (TextView) customSecondView.findViewById(R.id.textContainer);
secondTabView.setText(R.string.second);
secondTabView.setTextColor(cslist);
secondTab.setCustomView(customSecondView);
thirdTab = tabs.newTab().setTag(TAB_THIRD);
View customThirdTabView
= …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 okhttp 进行网络调用。我还需要 websocket 所以我是这样制作的:
public class WebSocketService extends Service implements WebSocketListener {
private static final String TAG = "WebSocketService";
private static final String BASE_URL = "ws://192.168.1.39:8080/websocket";
public static final int MSG_RESPONSE = 1;
public static final int MSG_HELLO = 2;
Messenger msger = new Messenger(new MessageHandler());
private WebSocket webSocket;
private boolean mWebSocketOpened = false;
private Messenger replyToMsngr;
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "service oncreate");
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(0, TimeUnit.NANOSECONDS)
.connectTimeout(15000, TimeUnit.MILLISECONDS)
.retryOnConnectionFailure(true)
.build();
Request request …Run Code Online (Sandbox Code Playgroud) 我有一个带有多个 TextInputLayouts 的 xml。其中之一如下:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textInputEmail"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginStart="@dimen/default_margin"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin_half"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="@dimen/default_margin_half"
app:layout_constraintBottom_toBottomOf="parent">
<android.support.design.widget.TextInputEditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"
android:text="@={viewModel.username}"
android:onTextChanged="@{(text, start, before, count) -> viewModel.onTextChanged(text)}"
android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中,我实现了文本更改侦听器,如下所示:
fun onTextChanged(text: CharSequence){
Log.i("LoginViewModel", "username = "+text)
}
Run Code Online (Sandbox Code Playgroud)
我想做的是这样的:
fun onTextChanged(text: CharSequence, view: View){
when(view.id){
R.id.editText1 -> doSomething1()
R.id.editText2 -> doSomething2()
}
Run Code Online (Sandbox Code Playgroud)
当数据绑定用于调用方法时,是否可以传递触发方法的视图的视图/ID/引用?
我有一个对象数组,例如
var objects: [AnimalDetailModel] = ...
Run Code Online (Sandbox Code Playgroud)
还有三堂课
AnimalDetailModel 是基类
DogDetailModel 是延伸的课程 AnimalDetailModel
CatDetailModel 是延伸的课程 AnimalDetailModel
从A datasource创建并添加DogDetailModel,,CatDetailModel和AnimalDetailModel的数组objects。并填充的tableView当我想要的是得到一个对象表单对象,并检查它是否是类型的DogDetailModel,CatDetailModel或AnimalDetailModel像
if let objects[indexPath.row] as? DogDetailModel {
return DogTableCell
} else if let objects[indexPath.row] as? CatDetailModel {
return CatTableCell
} else {
return AnimalTableCell
}
Run Code Online (Sandbox Code Playgroud)
这样做时,我得到的类型AnimalDetailModel没有下标成员。我们如何从对象数组中检查对象的类型?
我正在使用Library greendao将数据类型保存到本地数据库.设置实体并运行应用程序后,在api响应中添加了一个新属性.它变成了这样的东西.之前:
@Entity
public class Data{
@Id
long id;
String name;
String detail;
}
Run Code Online (Sandbox Code Playgroud)
后:
@Entity
public class Data{
@Id
long id;
String name;
String detail;
String image;
}
Run Code Online (Sandbox Code Playgroud)
更新数据类型后,我重新安装了应用程序,然后运行应用程序,但是android.database.sqlite.SQLiteException出错:没有这样的列:T.IMAGE(代码1):,编译时:SELECT T."_ id",T. "NAME",T."DETAIL",T."图像"来自"DATA"T
我该如何解决这个问题?