是否可以在我的适配器中创建多视图类型..就像为我的标题添加视图然后在标题下面是一个列表.
我的适配器的代码段:
public class StoreAdapter extends RecyclerView.Adapter<StoreAdapter.BindingHolder> {
List<Store> mStoreList;
public class BindingHolder extends RecyclerView.ViewHolder {
private ViewDataBinding binding;
public BindingHolder(View v) {
super(v);
binding = DataBindingUtil.bind(v);
}
public ViewDataBinding getBinding() {
return binding;
}
}
public StoreAdapter(List<Store> storeList) {
this.mStoreList = storeList;
}
@Override
public BindingHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row_store, parent, false);
BindingHolder holder = new BindingHolder(v);
return holder;
}
@Override
public void onBindViewHolder(BindingHolder holder, int position) {
final Store store = mStoreList.get(position);
holder.getBinding().setVariable(BR.store, …Run Code Online (Sandbox Code Playgroud) android android-adapter android-studio android-recyclerview android-databinding
目录
@Entity(tableName = "directory")
class Directory(@PrimaryKey(autoGenerate = false) var id: Int? = null,
@ColumnInfo(name = DIR_NAME) var dirName: String? = null,
@Ignore var dirImages: List<Images>? = null
) : Serializable {
companion object {
const val DIR_NAME = "dirName"
const val DIR_IMAGES = "dirImages"
}
}
Run Code Online (Sandbox Code Playgroud)
影像模型
@Entity(foreignKeys = arrayOf(ForeignKey(entity = Directory::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("id"),
onDelete = ForeignKey.CASCADE)))
data class Images(
@PrimaryKey(autoGenerate = false) val id: Int? = null,
@ColumnInfo(name = "image") val images: String
) { …Run Code Online (Sandbox Code Playgroud) android kotlin android-database android-components android-room
这是在MainActivity中用作BroadcastReceiver的代码
//Initializing our broadcast receiver
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
//When the broadcast received
//We are sending the broadcast from GCMRegistrationIntentService
@Override
public void onReceive(Context context, Intent intent) {
//If the broadcast has received with success
//that means device is registered successfully
if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_SUCCESS)){
//Getting the registration token from the intent
String token = intent.getStringExtra("token");
//Displaying the token as toast
Toast.makeText(getApplicationContext(), "Registration token:" + token, Toast.LENGTH_LONG).show();
//if the intent is not with success then displaying error messages
} else if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_ERROR)){
Toast.makeText(getApplicationContext(), …Run Code Online (Sandbox Code Playgroud) 布局:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:onNavigationItemSelected="@{viewModel.onNavigationItemSelected}"
android:background="?android:attr/windowBackground"
app:menu="@menu/menu_home_tab" />
Run Code Online (Sandbox Code Playgroud)
代码:
@BindingAdapter("onNavigationItemSelected")
public static void setOnNavigationItemSelected(
BottomNavigationView view, BottomNavigationView listener) {
view.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_dashboard:
Log.d("test","test1");
return true;
case R.id.navigation_notifications:
Log.d("test","test2");
return true;
}
return false;
}
});
}
Run Code Online (Sandbox Code Playgroud)
这将返回一个错误
Error:(183, 49) Could not find accessor viewmodel.onNavigationItemSelected
Run Code Online (Sandbox Code Playgroud)
我正在尝试在我的底部导航视图上实现数据绑定
android mvvm android-layout android-databinding bottomnavigationview