嗨stackoverflow
我真的想知道为什么Adapter
在我if
内放Adapter
条件时会重复这些内容,请有人指导我纠正错误,在这里是我的adapter
public class CustomStoreAdapter extends BaseAdapter {
/** Variable declaration */
private ArrayList<StoresUtility> storeList = new ArrayList<StoresUtility>();
private Context context;
public CustomStoreAdapter(Context context) {
this.context = context;
}// End of CustomAdapter constructor
public void setData(ArrayList<StoresUtility> serviceProviderList) {
this.storeList = serviceProviderList;
notifyDataSetChanged();
}
public int getCount() {
return storeList.size();
}// End of getCount method
public Object getItem(int position) {
return storeList.get(position);
}// End of getItem method
public long getItemId(int position) {
return position;
}// End of getItemId method
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.stores_adapter, null);
}// End of if block
TextView name = (TextView) v.findViewById(R.id.tv_store_full_name);
TextView firstLetter = (TextView) v.findViewById(R.id.tv_store_first_letter);
TextView mobileOne = (TextView) v.findViewById(R.id.tv_contact_store_one);
TextView mobileTwo = (TextView) v.findViewById(R.id.tv_contact_store_two);
LinearLayout llOne = (LinearLayout) v.findViewById(R.id.ll_mobie_one);
LinearLayout llTwo = (LinearLayout) v.findViewById(R.id.ll_mobie_two);
RelativeLayout rlOne = (RelativeLayout) v.findViewById(R.id.rl_contact_store_one);
RelativeLayout rlTwo = (RelativeLayout) v.findViewById(R.id.rl_contact_store_two);
try {
if(storeList.get(position).getName().length() > 0) {
char initial = storeList.get(position).getName().charAt(0);
firstLetter.setText(""+initial);
}
} catch(Exception e) { }
name.setText(""+storeList.get(position).getName());
if(!storeList.get(position).getMobileOne().equalsIgnoreCase("null")) {
llOne.setVisibility(0);
mobileOne.setText(""+storeList.get(position).getMobileOne());
}
if(!storeList.get(position).getMobileTwo().equalsIgnoreCase("null")) {
llTwo.setVisibility(0);
mobileTwo.setText(""+storeList.get(position).getMobileTwo());
}
return v;
}// End of getView method
}//End of CustomServiceAdapter class
提前致谢。
答案 0 :(得分:2)
你需要改变:
if(!storeList.get(position).getMobileOne().equalsIgnoreCase("null")) {
llOne.setVisibility(0);
mobileOne.setText(""+storeList.get(position).getMobileOne());
}
if(!storeList.get(position).getMobileTwo().equalsIgnoreCase("null")) {
llTwo.setVisibility(0);
mobileTwo.setText(""+storeList.get(position).getMobileTwo());
}
到
if(!storeList.get(position).getMobileOne().equalsIgnoreCase("null")) {
llOne.setVisibility(View.VISIBLE);
mobileOne.setText(""+storeList.get(position).getMobileOne());
}
else
llOne.setVisibility(View.GONE);
if(!storeList.get(position).getMobileTwo().equalsIgnoreCase("null")) {
llTwo.setVisibility(View.VISIBLE);
mobileTwo.setText(""+storeList.get(position).getMobileTwo());
}
else
llTwo.setVisibility(View.GONE);
请不要使用0
将视图的可见性更改为Visible,而不是0
使用View.VISIBLE