public View getView(final int position, View convertView,
ViewGroup parent) {
final LinearLayout itemView;
if(convertView == null){
itemView = (LinearLayout) mLayoutInflater.inflate(R.layout.sms_layout, parent, false);
final TextView smsMsg = (TextView)itemView.findViewById(R.id.textViewForSMS);
final Sms sms=mEntries.get(position);
if(sms.getAddress().contains("5556")){
/*itemView.setVisibility(View.VISIBLE);*/
smsMsg.setText(sms.getAddress()+" :\n "+sms.getMsg());
smsMsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
plum.ShowSendMsgLayout(sms.getMsg().split(":")[0]);
}
});
}
}else{
itemView=(LinearLayout)convertView;
/* if(sms.getMsg().contains(" ")){
itemView.setVisibility(View.INVISIBLE);
}*/
}
return itemView;
}
public void upDateEntries(List<Sms> entries) {
mEntries = new ArrayList<Sms>();
notifyDataSetChanged();
mEntries = entries;
notifyDataSetChanged();
}
这是我的列表适配器代码。我给出了一个条件,即仅来自模拟器5556的消息出现在我的列表视图中。但是其他模拟器的消息被视为空白,即没有任何动作性能的空行。请建议代码解决方案,以消除那些空行。
答案 0 :(得分:0)
这是我的列表适配器代码。我给出的条件只有消息 来自模拟器5556出现在我的列表视图中。但其他的消息 模拟器被视为空白
ListView中的行数取决于返回的值getCount
适配器的方法方法。 ListView显示所有消息,因为适配器数据源可能包含所有消息。
要修复此问题,请在适用时调用remove
适配器,如果邮件不包含5556
:
if(sms.getAddress().contains("5556")){
// your code here...
}else{
// remove item from adapter
remove(position);
notifyDataSetChanged();
}
答案 1 :(得分:0)
在将Sms添加到数据列表时,应验证条件。如果它与该条件不匹配,则不应添加短信。我为你改了代码,试试看:
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = mLayoutInflater.inflate(R.layout.sms_layout, parent, false);
}
final TextView smsMsg = (TextView)convertView.findViewById(R.id.textViewForSMS);
final Sms sms=mEntries.get(position);
smsMsg.setText(sms.getAddress()+" :\n "+sms.getMsg());
smsMsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
plum.ShowSendMsgLayout(sms.getMsg().split(":")[0]);
}
});
return convertView;
}
public void upDateEntries(List<Sms> entries) {
mEntries.clear();
for(Sms sms : entries){
if(sms.getAddress().contains("5556")){
mEntries.add(sms);
}
}
notifyDataSetChanged();
}