Java ListItem中的ListView仅显示一个条目
在我最初的活动中,我初始化了一个适配器来填充Java ListItem中的ListView仅显示一个条目,java,android,listview,android-arrayadapter,Java,Android,Listview,Android Arrayadapter,在我最初的活动中,我初始化了一个适配器来填充ListView,这一切都进行得很顺利ArrayList填充了所有数据,并作为参数传递给适配器,一切正常 现在,在该适配器或填充的ListView中,有另一个ListView和另一个适配器 同样,我按照相同的过程使用ArrayList填充适配器,但似乎只有第一个条目显示在嵌套的列表视图中。我假设这是因为父项ListView被填充,而子项ListView的数据只为一个父项填充 无论如何,下面是适配器初始化和适配器类: PlayerSeasonsS
ListView
,这一切都进行得很顺利ArrayList
填充了所有数据,并作为参数传递给适配器,一切正常
现在,在该适配器或填充的ListView
中,有另一个ListView
和另一个适配器
同样,我按照相同的过程使用ArrayList
填充适配器,但似乎只有第一个条目显示在嵌套的列表视图中。我假设这是因为父项ListView
被填充,而子项ListView
的数据只为一个父项填充
无论如何,下面是适配器初始化和适配器类:
PlayerSeasonsStatsAdapter pssAdapter = new PlayerSeasonsStatsAdapter(getContext(), alPlayerSeasonsStats);
vh.lvPlayerSeasonsStats.setAdapter(pssAdapter);
alplayerseasonstats
是一个数组列表,其中包含用于填充子列表视图的数据
下面是子适配器:
public class PlayerSeasonsStatsAdapter extends ArrayAdapter{
private ArrayList<PlayerStatsTeamModelSeasons> playerSeasons = new ArrayList<PlayerStatsTeamModelSeasons>();
private LayoutInflater mInflater;
public PlayerSeasonsStatsAdapter(Context context, ArrayList<PlayerStatsTeamModelSeasons> playerSeasons) {
super(context, 0, playerSeasons);
this.playerSeasons = playerSeasons;
mInflater = LayoutInflater.from(context);
}
@Override
public PlayerStatsTeamModelSeasons getItem(int position) {
return playerSeasons.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.player_seasons_stats_row, parent, false);
vh = new ViewHolder();
vh.tvPSSRCompetition = (TextView) convertView.findViewById(R.id.tvPSSRCompetition);
vh.tvPSSRMatchesPlayed = (TextView) convertView.findViewById(R.id.tvPSSRMatchesPlayed);
vh.tvPSSRGoalsScored = (TextView) convertView.findViewById(R.id.tvPSSRGoalsScored);
vh.tvPSSRAssists = (TextView) convertView.findViewById(R.id.tvPSSRAssists);
vh.tvPSSRYellowCards = (TextView) convertView.findViewById(R.id.tvPSSRYellowCards);
vh.tvPSSRRedCards = (TextView) convertView.findViewById(R.id.tvPSSRRedCards);
vh.ivPSSRCompetitionLogo = (ImageView) convertView.findViewById(R.id.ivPSSRCompetitionLogo);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
PlayerStatsTeamModelSeasons pstmsModel = getItem(position);
vh.tvPSSRCompetition.setText(pstmsModel.pstmSeasonModel.name);
vh.tvPSSRMatchesPlayed.setText(pstmsModel.pstmsModel.matchesPlayed);
vh.tvPSSRGoalsScored.setText(pstmsModel.pstmsModel.goalsScored);
vh.tvPSSRAssists.setText(pstmsModel.pstmsModel.assists);
vh.tvPSSRYellowCards.setText(pstmsModel.pstmsModel.yellowCards);
int totalRedCards = Integer.parseInt(pstmsModel.pstmsModel.yellowRedCards) + Integer.parseInt(pstmsModel.pstmsModel.redCards);
vh.tvPSSRRedCards.setText(totalRedCards + "");
//loadLogoToView(vh.ivPSSRCompetitionLogo, pstmsModel.pstmSeasonModel.id, true);
return convertView;
}
public static void loadLogoToView(ImageView iv, String teamId, boolean transform) {
String image = Constant.IMAGES_ROOT +
Constant.LOGO_PATH +
teamId +
Constant.LOGO_EXTENSION;
RequestCreator img = Picasso.with(iv.getContext())
.load(image);
if (transform) img.transform(new RoundedCornersTransform(2));
img.into(iv);
}
static class ViewHolder {
ImageView ivPSSRCompetitionLogo;
TextView tvPSSRCompetition;
TextView tvPSSRMatchesPlayed;
TextView tvPSSRGoalsScored;
TextView tvPSSRAssists;
TextView tvPSSRYellowCards;
TextView tvPSSRRedCards;
}
公共类PlayerSeasonsStatsAdapter扩展了ArrayAdapter{
private ArrayList playerSeasons=new ArrayList();
私人停车场;
PublicPlayerSeasonsStatsAdapter(上下文上下文,数组列表playerSeasons){
超级(上下文,0,playerSeasons);
this.playerSeasons=playerSeasons;
mInflater=LayoutInflater.from(上下文);
}
@凌驾
公共playerStatsGetItem(内部位置){
返回球员赛季。获得(位置);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
convertView=mInflater.flate(R.layout.player\u seasures\u stats\u row,parent,false);
vh=新的视窗支架();
vh.tvpsrcompetition=(TextView)convertView.findviewbyd(R.id.tvpsrcompetition);
vh.tvPSSRMatchesPlayed=(TextView)convertView.findViewById(R.id.tvPSSRMatchesPlayed);
vh.tvPSSRGoalsScored=(TextView)convertView.findViewById(R.id.tvPSSRGoalsScored);
vh.tvpssrasists=(TextView)convertView.findViewById(R.id.tvpssrasists);
vh.tvPSSRYellowCards=(TextView)convertView.findViewById(R.id.tvPSSRYellowCards);
vh.tvpsredcards=(TextView)convertView.findViewById(R.id.tvpsredcards);
vh.ivPSSRCompetitionLogo=(ImageView)convertView.findViewById(R.id.ivPSSRCompetitionLogo);
convertView.setTag(vh);
}否则{
vh=(ViewHolder)convertView.getTag();
}
PlayerStatSteamModelPSTSModel=getItem(位置);
vh.tvpsrcompetition.setText(pstsmodel.pstmSeasonModel.name);
vh.tvPSSRMatchesPlayed.setText(pstsmodel.pstsmodel.matchesPlayed);
vh.tvpsrgoalsscored.setText(pstsmodel.pstsmodel.goalsScored);
vh.tvpsrassists.setText(pstsmodel.pstsmodel.assists);
vh.tvpsrylowcards.setText(pstsmodel.pstsmodel.yellowCards);
int totalRedCards=Integer.parseInt(pstsmodel.pstsmodel.yellowdredcards)+Integer.parseInt(pstsmodel.pstsmodel.redCards);
vh.tvpsredcards.setText(totalRedCards+“”);
//LoadLogotView(vh.ivpssrCompetition徽标,pstmmodel.pstmSeasonModel.id,true);
返回视图;
}
公共静态void loadLogoToView(ImageView iv,字符串teamId,布尔转换){
字符串image=Constant.IMAGES\u ROOT+
常量.LOGO\u路径+
teamId+
常量LOGO_扩展;
RequestCreator img=Picasso.with(iv.getContext())
.加载(图像);
if(变换)图像变换(新圆角变换形式(2));
img.进入(iv);
}
静态类视窗夹{
ImageView IVPSSRCompetition徽标;
文本视图TVPSRCompetition;
显示文本视图TVPS;
文本视图TVPSSRGOALSCODE;
TextView tvPSSRAssists;
文本视图TVPSRYELLOW卡;
文本视图TVPSREDCards;
}
我的选项是什么?您的适配器应该是
public class PlayerSeasonsStatsAdapter extends ArrayAdapter<PlayerStatsTeamModelSeasons> {
private class ViewHolder {
TextView tvPSSRCompetition;
}
public PlayerSeasonsStatsAdapter(Context context, List<PlayerStatsTeamModelSeasons> balanceModels) {
super(context, R.layout.row_account_balance, balanceModels);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
PlayerStatsTeamModelSeasons model = getItem(position);
PlayerSeasonsStatsAdapter.ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new PlayerSeasonsStatsAdapter.ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.row_account_balance, parent, false);
viewHolder.tvPSSRCompetition = (TextView) convertView.findViewById(R.id.tvPSSRCompetition);
convertView.setTag(viewHolder);
} else {
viewHolder = (PlayerSeasonsStatsAdapter.ViewHolder) convertView.getTag();
}
viewHolder.tvPSSRCompetition.setText(model.getPSSRCompetition());
if (position%2== 0) {
convertView.setBackgroundColor(Color.parseColor("#F5EEE5"));
}else{
convertView.setBackgroundColor(Color.parseColor("#FFFFFF"));
}
return convertView;
}
}
Listview看起来像bellow
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
这是行\账户\余额布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvPSSRCompetition"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical|center_horizontal"
android:text="@string/agent_statement_sl"
android:textStyle="bold"
android:paddingLeft="2dp"
android:textSize="16sp"
android:paddingBottom="5dp"
android:paddingTop="5dp"/>
</LinearLayout>
首先,我不会在另一个列表视图中嵌套列表视图
。将单个列表视图
与多行类型一起使用,或者使用可扩展列表视图
,或者使用具有某种扩展语义的回收视图
,或者将回收视图
与多个项目类型一起使用,或者使用ode>垂直
线性布局
而不是嵌套的列表视图
,或者使用沿另一个轴工作的东西(例如,水平滚动视图
),或者使用两个活动/片段(顶层列表视图
与以前嵌套的列表视图一起向下钻取一组单独的细节
),等等。我听说嵌套的ListView会导致UI问题,但由于我的设计如此简单,这不会是一个问题。也就是说,在选择从头开始之前,我能做些什么来修复现有的逻辑吗?可以看看这个:但问题不在于它显示一个ListView
,只有一个项目有空间,问题在于用于通过适配器填充列表视图的ArrayList
只包含一个条目。如果size()
为1,则问题在于如何填充alPlayerAsonStats
。您在哪里进行了更改?可能添加一些解释,说明如何解决此问题将有助于操作。。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvPSSRCompetition"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical|center_horizontal"
android:text="@string/agent_statement_sl"
android:textStyle="bold"
android:paddingLeft="2dp"
android:textSize="16sp"
android:paddingBottom="5dp"
android:paddingTop="5dp"/>
</LinearLayout>