我的列表视图的数据在滚动列表视图上下不断变化。似乎适配器出了问题。下面是我用于Adapter的代码。 我在listview项目中有两个按钮,接受和拒绝请求。如果请求被接受或拒绝,那么只会出现一个按钮。如果请求待定,即P,则两个按钮都将显示
public View getView(int position, View convertView_, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder view ;
System.out.println("getView " + position + " " + convertView_);
if (convertView_ == null) {
convertView_ = inflator.inflate(R.layout.received_list_row, null);
view = new ViewHolder();
view.imageViewPage = (ImageView) convertView_
.findViewById(R.id.received_postImage);
view.postImageBg = (ImageView) convertView_
.findViewById(R.id.received_postImageBg);
view.txt_post_title = (CTextView) convertView_
.findViewById(R.id.received_txt_post_title);
view.txt_post_Date = (CTextView) convertView_
.findViewById(R.id.received_txt_post_Date);
view.txt_post_Time = (CTextView) convertView_
.findViewById(R.id.received_txt_post_Time);
view.llparent = (LinearLayout) convertView_
.findViewById(R.id.received_llparent);
view.llaccrej_btns = (LinearLayout) convertView_
.findViewById(R.id.ll_accrejbtns);
view.txt_acceptreq = (CTextView) convertView_
.findViewById(R.id.textview_acceptreq);
view.invisible_txtbtn = (CTextView) convertView_
.findViewById(R.id.invisible_btn);
view.txt_rejectreq = (CTextView) convertView_
.findViewById(R.id.textview_rejectreq);
convertView_.setTag(view);
} else {
view = (ViewHolder) convertView_.getTag();
}
view.txt_post_title.setText(list.get(position).getActivity_name());
view.txt_post_Date.setText(list.get(position).getActivity_postdate());
view.txt_post_Date.setText(list.get(position).getActivity_postdate());
view.txt_post_Time.setText(list
.get(position)
.getActivity_posttime()
.substring(
0,
list.get(position).getActivity_posttime()
.lastIndexOf(":")));
if(request_status.equals("P"))
{
}
else if (request_status.equals("A") && view.txt_acceptreq.getTag().equals(position))
{
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
view.txt_rejectreq.setVisibility(View.GONE);
view.txt_rejectreq.setClickable(false);
view.invisible_txtbtn.setVisibility(View.GONE);
view.txt_acceptreq.setText("ACCEPTED");
view.txt_acceptreq.setClickable(false);
view.txt_acceptreq.setGravity(Gravity.CENTER);
view.txt_acceptreq.setLayoutParams(params);
}
else if (request_status.equals("R") && view.txt_rejectreq.getTag().equals(position)) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
view.txt_acceptreq.setVisibility(View.GONE);
view.txt_acceptreq.setClickable(false);
view.invisible_txtbtn.setVisibility(View.GONE);
view.txt_rejectreq.setText("REJECTED");
view.txt_rejectreq.setClickable(false);
view.txt_rejectreq.setGravity(Gravity.CENTER);
view.txt_rejectreq.setLayoutParams(params);
}
view.txt_acceptreq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
System.out.println("CLICKED ACCEPTED" + position);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
view.txt_acceptreq.setText("ACCEPTED");
view.txt_acceptreq.setClickable(false);
view.txt_acceptreq.setGravity(Gravity.CENTER);
view.txt_acceptreq.setLayoutParams(params);
view.txt_rejectreq.setVisibility(View.GONE);
view.txt_rejectreq.setClickable(false);
view.invisible_txtbtn.setVisibility(View.GONE);
int user_id = list.get(position).getUser_id();
int activity_id = list.get(position).getActivity_id();
String status = "A";
macc_rejRequestTask = new AcceptRejectActivityRequestTask(
maccept_rejRequestResponder, activity);
AsyncUtil.execute(macc_rejRequestTask, "" + user_id, ""
+ activity_id, status);
}
});
view.txt_rejectreq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
System.out.println("CLICKED REJECTED " + position);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
view.txt_rejectreq.setText("REJECTED");
view.txt_rejectreq.setClickable(false);
view.txt_rejectreq.setGravity(Gravity.CENTER);
view.txt_rejectreq.setLayoutParams(params);
view.txt_acceptreq.setVisibility(View.GONE);
view.txt_acceptreq.setClickable(false);
view.invisible_txtbtn.setVisibility(View.GONE);
int user_id = list.get(position).getUser_id();
int activity_id = list.get(position).getActivity_id();
String status = "R";
macc_rejRequestTask = new AcceptRejectActivityRequestTask(
maccept_rejRequestResponder, activity);
AsyncUtil.execute(macc_rejRequestTask, "" + user_id, ""
+ activity_id, status);
}
});
return convertView_;
}