我试图在回收站 View 中显示字符串列表。由于某种原因,它不起作用。它没有显示任何内容。 我不知道为什么它不起作用,这不是我第一次使用它,通常我是用 firebase recycler 做的。
这是我的代码
rvTypeMusic = (RecyclerView)findViewById(R.id.rvMusicType);
ArrayList<String> songs = new ArrayList<String>();
songs.add("PHP");
songs.add("C#");
songs.add("Java");
songs.add("JavaScript");
songs.add("Android");
adapter = new TypeMusicListAdapter(this,songs);
rvTypeMusic.setAdapter(adapter);
rvTypeMusic.setLayoutManager(new GridLayoutManager(this,2));
}
public static class TypeMusicListAdapter extends
RecyclerView.Adapter<TypeMusicListViewHolder>{
private LayoutInflater inflater;
private Context context;
private List<String> data;
public TypeMusicListAdapter(Context context, List<String> data){
this.context = context;
this.inflater = LayoutInflater.from(context);
this.data = data;
}
@Override
public TypeMusicListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = inflater.inflate(R.layout.type_music_item,parent,false);
return new TypeMusicListViewHolder(v);
}
@Override
public void onBindViewHolder(TypeMusicListViewHolder holder, int position) {
String songType = data.get(position);
//holder.musicType.setText(songType.getSongName());
holder.musicType.setText(songType);
}
@Override
public int getItemCount() {
return 0;
}
}
public static class TypeMusicListViewHolder extends RecyclerView.ViewHolder {
private TextView musicType;
public TypeMusicListViewHolder(View itemView) {
super(itemView);
musicType = (TextView) itemView.findViewById(R.id.musicType);
}
}
XML 文件
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.world.bolandian.talent.MainActivity"
tools:showIn="@layout/app_bar_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvMusicType"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/type_music_item">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
XML 项目
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/musicType"
android:padding="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
</android.support.v7.widget.CardView>
</LinearLayout>
我在这里错过了什么?我尝试了一些东西,但没有任何效果。
最佳答案
答案是@abdur Rahman 和@ADM 的混合体。 首先,我们必须在像这样设置适配器之前将布局管理器设置为 RecyclerView。
rvTypeMusic.setLayoutManager(new GridLayoutManager(this,2));
rvTypeMusic.setAdapter(adapter);
因为回收 View 将在我们设置适配器后立即开始放置 View ,因此到那时它必须具有布局管理器。 第二, 这个
@Override
public int getItemCount() {
return data.size();
}
onCreateViewHolder 和 onBindViewHolder 只有在返回非零值时才会被调用
关于java - Recyclerview 不显示任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47114241/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在处理旧代码的一部分。beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)endRubocop错误如下:Avoidstubbingusing'allow_any_instance_of'我读到了RuboCop::RSpec:AnyInstance我试着像下面那样改变它。由此beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)end对此:let(:sport_