我正在尝试将此 JSON 响应解析到 android 中的 ListView 上,我试图通过根据性别显示图像并为男性记录添加按钮来修改列表视图。
逻辑工作正常,除了最后两个条目。约翰韦恩和莱昂纳多迪卡普里奥有详细信息按钮,约翰尼德普和拉维坦布达也是如此。请指导我。
使用此代码,我试图根据性别区分它们
if(rowData.mgender.equalsIgnoreCase("male"))
{
imageViewStatus.setImageResource(R.drawable.male);
}
else{
imageViewStatus.setImageResource(R.drawable.female);
button.setVisibility(View.GONE);
}
编辑 1
public View getView(final int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
TextView title = null;
TextView detail = null;
TextView data=null;
TextView message=null;
ImageView imageViewStatus=null;
Button button=null;
final RowData rowData= getItem(position);
if(null == convertView)
{
convertView = layoutInflater.inflate(R.layout.record, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
button=(Button)holder.getProceedButton();
message=holder.getEmail();
message.setText(rowData.mEmail);
title = holder.getName();
title.setText(rowData.mName);
detail = holder.getAddress();
detail.setText(rowData.mAdress);
data= holder.getPhoneNumber();
data.setText(rowData.mMobile+" "+rowData.mOffice);
imageViewStatus=holder.getImage();
System.out.println("This is the gender "+rowData.mgender);
if(rowData.mgender.equalsIgnoreCase("male"))
{
imageViewStatus.setImageResource(R.drawable.male);
}
else{
imageViewStatus.setImageResource(R.drawable.female);
System.out.println("Button Visibility"+button.getVisibility());
button.setVisibility(View.GONE);
}
return convertView;
}