我遇到問題列表視圖項。在此列表視圖中,我將創建一個線性佈局,並且該佈局將添加到我的原始佈局中。數據第一次非常清晰,但是當我滾動數據時,數據未能匹配。任何人都可以幫我解決這個問題嗎?我用擴展底座適配器列表查看項目正在重複滾動
代碼
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items, parent, false);
holder = new ViewHolder();
holder.wishlistName = (TextView) view.findViewById(R.id.wishlist_name);
holder.wishlistEmail = (TextView) view.findViewById(R.id.wishlist_email);
holder.wishlistRelation = (TextView) view.findViewById(R.id.wishlist_relation);
holder.wishGiftAdvisorText = (TextView) view.findViewById(R.id.gift_advisor_text);
//holder.advisorListview = (ListView) view.findViewById(R.id.listView);
holder.inviteAdvisor = (ImageButton) view.findViewById(R.id.invite_advisor);
holder.advisorContainer = (LinearLayout) view.findViewById(R.id.advisor_container);
holder.editButton = (ImageButton) view.findViewById(R.id.editButton);
holder.deleteButton = (ImageButton) view.findViewById(R.id.deleteButton);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// holder.advisorContainer.removeAllViews();
holder.wishlistName.setText(names[position]);
if(!emails[position].equals("0")) {
holder.wishlistEmail.setText(emails[position]);
} else {
holder.wishlistEmail.setText("");
}
holder.wishlistRelation.setText(relationships[position]);
holder.wishGiftAdvisorText.setText(getResources().getString(R.string.wishlist_getadvisor)+" "+names[position]+"'s "+getResources().getString(R.string.wishlist_title1));
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
holder.advisorContainer.setLayoutParams(lp);
if(advisors[position].contains("[")) {
try {
array = new JSONArray(advisors[position]);
System.out.println(array.toString(2));
// TODO Auto-generated method stub
// holder.advisorContainer.removeAllViews();
if(array!= null) {
for (int i = 0; i < array.length(); i++) {
JSONObject c = null;
try {
c = array.getJSONObject(i);
if(!advisorList.contains(c.getString("advisor_id"))) {
advisorList.add(c.getString("advisor_id"));
LinearLayout linearLayout_837 = new LinearLayout(WishList.this);
linearLayout_837.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout_837.setBackgroundColor(0xFFFFFFFF);
linearLayout_837.setOrientation(LinearLayout.HORIZONTAL);
linearLayout_837.setPadding(0, 5, 0, 0);
LinearLayout linearLayout_746 = new LinearLayout(WishList.this);
linearLayout_746.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layout_788 = new LinearLayout.LayoutParams(0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.73f);
layout_788.leftMargin = 10;
linearLayout_746.setWeightSum(1);
linearLayout_746.setPadding(10, 0, 0, 0);
linearLayout_746.setLayoutParams(layout_788);
final TextView advisor_name_text = new TextView(WishList.this);
advisor_name_text.setEllipsize(TruncateAt.END);
advisor_name_text.setMaxLines(2);
advisor_name_text.setText(c.getString("name"));
advisor_name_text.setTextColor(getResources().getColor(R.color.Black));
LinearLayout.LayoutParams layout_527 = new LinearLayout.LayoutParams(
0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT,0.4f);
layout_527.gravity = Gravity.CENTER;
advisor_name_text.setLayoutParams(layout_527);
linearLayout_746.addView(advisor_name_text,layout_527);
TextView advisor_email_text = new TextView(WishList.this);
//advisor_email_text.setId(R.id.advisor_email_text);
advisor_email_text.setEllipsize(TruncateAt.END);
advisor_email_text.setMaxLines(2);
advisor_email_text.setText(c.getString("email"));
//advisor_email_text.setTypeface(tf);
advisor_email_text.setTextColor(getResources().getColor(R.color.Black));
LinearLayout.LayoutParams layout_908 = new LinearLayout.LayoutParams(
0, LayoutParams.WRAP_CONTENT,0.6f);
advisor_email_text.setLayoutParams(layout_908);
linearLayout_746.addView(advisor_email_text,layout_908);
LinearLayout linearLayout_739 = new LinearLayout(WishList.this);
linearLayout_739.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layout_778 = new LinearLayout.LayoutParams(
0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.30f);
linearLayout_739.setLayoutParams(layout_778);
RelativeLayout relativeLayout_168 = new RelativeLayout(WishList.this);
RelativeLayout.LayoutParams layout_697 = new RelativeLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT
, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
relativeLayout_168.setLayoutParams(layout_697);
final ImageButton deleteButton = new ImageButton(WishList.this);
deleteButton.setId(Integer.parseInt(c.getString("advisor_id")));
deleteButton.setBackgroundResource(R.drawable.wishlistremoveicon);
deleteButton.setContentDescription(getResources().getString(R.string.app_name));
RelativeLayout.LayoutParams layout_439 = new RelativeLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
//layout_439.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
layout_439.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout_439.rightMargin = 10;
deleteButton.setLayoutParams(layout_439);
TextView status_text = new TextView(WishList.this);
status_text.setText(c.getString("status"));
if(c.getString("status").equalsIgnoreCase("accepted"))
{
status_text.setTextColor(Color.GREEN);
}
else if(c.getString("status").equalsIgnoreCase("pending"))
{
status_text.setTextColor(getResources().getColor(R.color.Orange));
}
else
{
status_text.setTextColor(getResources().getColor(R.color.Red));
}
RelativeLayout.LayoutParams layout_315 = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layout_315.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
layout_315.addRule(RelativeLayout.LEFT_OF, deleteButton.getId());
layout_315.rightMargin = 5;
status_text.setLayoutParams(layout_315);
relativeLayout_168.addView(deleteButton,layout_439);
relativeLayout_168.addView(status_text,layout_315);
linearLayout_739.addView(relativeLayout_168);
linearLayout_837.addView(linearLayout_746);
linearLayout_837.addView(linearLayout_739);
holder.advisorContainer.addView(linearLayout_837);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Click Operation
}
});
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
}
return view;
}
任何一個可以幫助儘快
你需要使用這種方式adpter請檢查http://www.mysamplecode.com/2012/07/android-listview-custom-layout-filter.html – PankajAndroid
你都盡顯您的advisorContainer,您必須重置它。刪除已添加的視圖或更新advisorContainer內部的視圖。 – RaphMclee
陣列適配器,但我必須使用基本適配器 – Android