在数组列表数据和适配器数据更改后,Listview数据未刷新。
我的代码:
listView = (ListView) detailsView.findViewById(R.id.settings_fragment_list);
ticketCommentsPriorityData.clear();
for (int i = 0; i <mTicketData.size(); i++) {
totalTicketsData =mTicketData.get(i).getTotalTicketsData();
for (int j = 0; j <mTicketData.get(i).getTotalTicketsData().size(); j++) {
if (ticketID.equalsIgnoreCase(mTicketData.get(i).getTotalTicketsData().get(j).getTicketID())) {
TicketCommentsPriorityData commentsPriorityData = new TicketCommentsPriorityData();
String comment =mTicketData.get(i)
.getTotalTicketsData().get(j).getComments();
String priority =mTicketData.get(i)
.getTotalTicketsData().get(j).getPriority();
commentsPriorityData.setComments(comment);
commentsPriorityData.setPriority(priority);
ticketCommentsPriorityData.add(commentsPriorityData);
}
}
}
}
if (ticketCommentsPriorityData != null
&& ticketCommentsPriorityData.size() > 0) {
detailListAdapter = new TicketDetailListAdapter(getActivity(),
R.layout.ticket_list_items, ticketCommentsPriorityData);
listView.setAdapter(detailListAdapter);
}
适配器类
public class TicketDetailListAdapter extends ArrayAdapter<TicketCommentsPriorityData> {
Context context;
ArrayList<TicketCommentsPriorityData> ticketData;
LayoutInflater layoutInflater;
int layoutResourceID;
public TicketDetailListAdapter(Context context,int layoutResourceID,
ArrayList<TicketCommentsPriorityData> ticketData) {
// TODO Auto-generated constructor stub
super(context, layoutResourceID, ticketData);
this.context = context;
this.ticketData = ticketData;
this.layoutResourceID = layoutResourceID;
layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder = null;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = layoutInflater.inflate(layoutResourceID,
parent, false);
viewHolder.ticketID = (TextView) convertView
.findViewById(R.id.ticket_id);
viewHolder.ticketDate = (TextView) convertView
.findViewById(R.id.ticket_date);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.ticketDate.setText(ticketData.get(position).getComments());
viewHolder.ticketID.setText(ticketData.get(position).getPriority());
return convertView;
}
class ViewHolder {
TextView ticketID;
TextView ticketDate;
}
}
编辑#1:
OnItemClick:
mTicketsListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long id) {
String ticketIDList = mTicketData.get(position).getTicketID();
String createdOn = mTicketData.get(position).getCreatedOn();
TicketDetailListFragment detailFragment = new TicketDetailListFragment();
Bundle bundle = new Bundle();
bundle.putString("ticket_id", ticketIDList);
FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.tickets_details_container,
detailFragment);
fragmentTransaction.commit();
}
});
我的问题是,当我点击父列表项时,此列表视图会执行并显示父列表项的详细信息。但是如果我点击第一项并且它获得第一项详细信息并显示它但是,如果我点击其他项目,它会始终显示项目详细信息首先显示在详细信息列表中,它始终只显示该数据。
任何人都给我一个解决方案。