卡的RecyclerView没有显示任何内容 [英] RecyclerView of cards not showing anything

查看:186
本文介绍了卡的RecyclerView没有显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过创建一个todo应用程序来试用支持库的recyclerview和cardview,该应用程序加载通过sqlite db保留的任务项.

I am trying out the support library's recyclerview and cardview by creating a todo app that loads Task items persisted through a sqlite db.

每张卡均由任务描述字符串和右上角的"x"图像组成,以将其从recyclerview中移除.

Each card consists of a task description string and an 'x' image in the top right corner to remove the card from the recyclerview.

我正在测试第一部分,添加一个任务.当按下commit时,我在调试器中看到该任务已持久.然后,我调用adapter.notifyItemAdded,传入数据源的最新索引.该应用程序运行后未显示任何卡,并且日志猫中未显示任何错误.

I'm testing out the first part, adding a task. When submit is pressed, I see in my debugger that the task is persisted. I then call adapter.notifyItemAdded, passing in the latest index of my data source. The app doesn't show any card after running and no errors were shown in the logcat.

MyActivity.xml:

MyActivity.xml:

....a bunch of RoboGuice injections
@InjectView(R.id.palettePurple)
private RelativeLayout palettePurple;

private ImageView deleteBtn;

private String currentColor;

TaskAdapter adapter;
List<Task> allTasks;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // register click listeners, "this" activity will listen for clicks on these views
    editBtn.setOnClickListener(this);
    submitBtn.setOnClickListener(this);
    deleteBtn.setOnClickListener(this);

    paletteRed.setOnClickListener(this);
    paletteOrange.setOnClickListener(this);
    paletteGreen.setOnClickListener(this);
    paletteRoyalBlue.setOnClickListener(this);
    palettePurple.setOnClickListener(this);


    RecyclerView recList = (RecyclerView) findViewById(R.id.tasksRV);
    recList.setHasFixedSize(true);
    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    recList.setLayoutManager(llm);

    allTasks = Task.getAll();
    adapter = new TaskAdapter(allTasks);
    recList.setAdapter(adapter);
}

....menu overrides....

@Override
public void onClick(View v) {
    Log.d("TRACE", "inside onClick");

    ....handling other clicks....

    // submit button was clicked, create a new task
    else if(v.getId() == R.id.submitBtn) {
            String taskDescription = taskET.getText().toString();
            Task newTask = new Task(taskDescription, currentColor);
            newTask.save();
            int lastIndex = allTasks.size()-1;
            adapter.notifyItemInserted(lastIndex);
            editSection.setVisibility(View.GONE);
            editBtn.setVisibility(View.VISIBLE);
        }
    }
}

我的卡xml和适配器java:如何做我在RecyclerView中选择了职位吗?

My card xml and adapter java: How do I get the position selected in a RecyclerView?

推荐答案

我很确定android studio支持recyclerview. 在您的项目build.gradle文件中添加:

I am pretty sure that android studio support recyclerview. In your project build.gradle file add :

dependencies {
...
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
}

这是一个美丽的博客,您可以在其中学习&使用recyclerview& cardview: http://www.binpress.com/tutorial/android -l-recyclerview-and-cardview-tutorial/156

Here is a beautiful blog where you can learn & use recyclerview & cardview : http://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156

希望这会有所帮助.

更新

版本号可以随时更改.获得最新消息的最佳方法:

Version number can be changed overtime. Best way to get the latest :

右键单击项目->打开模块设置->转到模块部分&选择模块->在右侧,转到依赖项标签"->单击"+"按钮,选择库依赖项"->搜索所需的库&添加.

right click on project - > open module settings - > go module section & select module -> on right side go "Dependency tab" -> click '+' button, select 'library dependency' -> search your required lib & add.

确保您的SDK的支持存储库&支持库已更新.

Make sure your SDK's support repository & support lib are updated.

这篇关于卡的RecyclerView没有显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆