Java 组在Firebase中按日期返回记录
我有一个Android应用程序,可以从Firebase数据库返回足球装备的Java 组在Firebase中按日期返回记录,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,我有一个Android应用程序,可以从Firebase数据库返回足球装备的列表视图。该列表目前可以使用,但我想改进UI。下图显示了我所拥有的以及我想要实现的目标 在左侧,我有一个布局xml,它在记录中循环并显示每个记录的日期,但我要做的是返回一个列表,该列表显示1个日期下的固定装置,如果它们相同,则显示在新日期下(如右侧) 下面是我的xml的布局 给你一个关于代码的想法(请问你是否想看代码,我最近贴了50多行) 红色的日期标题位于listview xml中 我猜这是一个递归函数,它计算出
列表视图。该列表目前可以使用,但我想改进UI。下图显示了我所拥有的以及我想要实现的目标
在左侧,我有一个布局xml,它在记录中循环并显示每个记录的日期,但我要做的是返回一个列表,该列表显示1个日期下的固定装置,如果它们相同,则显示在新日期下(如右侧)
下面是我的xml的布局
给你一个关于代码的想法(请问你是否想看代码,我最近贴了50多行)
红色的日期标题位于listview xml中
我猜这是一个递归函数,它计算出日期的所有子项,然后绘制列表
我的问题是,你会推荐哪种方法,因为我不想破坏性能,我在2-3种方法之间左右为难
编辑:ListView的适配器
public class matchList extends ArrayAdapter<matches> {
private Activity context;
private List<matches> matchList;
public matchList(Activity context, List<matches> matcheslist) {
super(context, R.layout.match_layout, matcheslist);
this.context = context;
this.matchList = matcheslist;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.match_layout, null, true);
TextView textViewDate = (TextView) listViewItem.findViewById(R.id.txtDate);
TextView textGameID = (TextView) listViewItem.findViewById(R.id.txtGameID);
TextView textViewTime = (TextView) listViewItem.findViewById(R.id.txtTime);
TextView textViewHomeTeam = (TextView) listViewItem.findViewById(R.id.txtAction);
TextView textViewAwayTeam = (TextView) listViewItem.findViewById(R.id.txtAwayTeam);
TextView textViewPitchNo = (TextView) listViewItem.findViewById(R.id.txtPitch);
ImageView imgLiveIco = (ImageView) listViewItem.findViewById(R.id.imgLive);
matches match = matchList.get(position);
textViewDate.setText(match.getDate());
textGameID.setText(match.getGameID());
textViewHomeTeam.setText(match.getHomeTeam());
textViewAwayTeam.setText(match.getAwayTeam());
textViewTime.setText(match.getTime());
String fdate = helper.dateFormater(match.getDate() , "EE dd MMM yyyy" , "dd/MM/yyyy");
textViewDate.setText(fdate);
textViewPitchNo.setText("Pitch " + match.getPitch().toString());
if(match.getPlayed() == 1) {
imgLiveIco.setVisibility(View.VISIBLE);
} else {
imgLiveIco.setVisibility(View.INVISIBLE);
}
return listViewItem;
}
}
公共类匹配列表扩展了ArrayAdapter{
私人活动语境;
私有列表匹配列表;
公共匹配列表(活动上下文、列表匹配列表){
super(上下文、R.layout.match_布局、matcheslist);
this.context=上下文;
this.matchList=matcheslist;
}
@非空
@凌驾
公共视图getView(int位置,@Nullable视图convertView,@NonNull视图组父级){
LayoutInflater充气器=上下文。getLayoutInflater();
View listViewItem=充气机。充气(R.layout.match_layout,null,true);
TextView textViewDate=(TextView)listViewItem.findViewById(R.id.txtDate);
TextView textGameID=(TextView)listViewItem.findViewById(R.id.txtGameID);
TextView textViewTime=(TextView)listViewItem.findViewById(R.id.txtTime);
TextView textViewHomeTeam=(TextView)listViewItem.findViewById(R.id.txtAction);
TextView textViewAwayTam=(TextView)listViewItem.findViewById(R.id.txTawayTam);
TextView textViewPitchNo=(TextView)listViewItem.findViewById(R.id.txtPitch);
ImageView imgLiveIco=(ImageView)listViewItem.findViewById(R.id.imgLive);
matches match=matchList.get(位置);
textViewDate.setText(match.getDate());
textGameID.setText(match.getGameID());
textViewHomeTeam.setText(match.getHomeTeam());
textViewAwayTam.setText(match.getAwayTam());
textViewTime.setText(match.getTime());
字符串fdate=helper.dateformatter(match.getDate(),“EE-dd-MMM-yyyy”,“dd/MM/yyyy”);
textViewDate.setText(fdate);
textViewPitchNo.setText(“Pitch”+match.getPitch().toString());
if(match.getPlayed()==1){
imgLiveIco.setVisibility(View.VISIBLE);
}否则{
imgLiveIco.setVisibility(视图不可见);
}
返回listViewItem;
}
}
为了实现您想要的,我建议您使用一个简单的if语句。从您的代码中我不明白的是,dateofmatch
是否是整个项目视图的一部分。如果它是该视图的一部分,则需要使用findviewbyd()
方法查找该视图,并使用如下If语句:
if (dateOfPreviousMatch.equals(dateOfMath)) {
//set visibility of dateofmatch to GONE
} else {
//set visibility of dateofmatch to VISIBLE
}
请分享将数据库中的数据设置到ListView/RecyclerView的代码。@AlexMamo刚刚用适配器codedateofmatch更新了这个问题,它是定义整个列表的布局的一部分,虽然我确实看到了上面代码的发展方向,但我会继续考虑这个想法
if (dateOfPreviousMatch.equals(dateOfMath)) {
//set visibility of dateofmatch to GONE
} else {
//set visibility of dateofmatch to VISIBLE
}