我有 3 种不同的布局cardsListLayout,titleLayout,cardMagazineLayout将来可能会有更多,用作方法的视图onCreateViewHolder。
我想在onCreateViewHolder方法中的视图之间切换,所以当用户从 AlertDialog 列表中选择时
这个 onOptionsItemSelected 在 MainActivity 那里有菜单项“更改布局”,以便当用户按下它时出现 AlertDialog 列表
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.change_layout) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.choose_layout));
String[] layouts = {"Title Layout", "Cards List", "Card Magazine Layout"};
builder.setItems(layouts, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int index) {
switch (index) {
case 0: // Title layout
Toast.makeText(MainActivity.this,
"Title layout", Toast.LENGTH_LONG).show();
break;
case 1: // Cards List …Run Code Online (Sandbox Code Playgroud) android android-layout android-viewholder android-recyclerview recyclerview-layout
android ×1