public class SampleInbox extends ListActivity {
private EfficientAdapter adap;
String strUrl;
InboxBean iBean;
InboxBean inboxBean;
XmlParser parser;
ArrayList<Object> result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main_content);
adap = new EfficientAdapter(this);
setListAdapter(adap);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Toast.makeText(this, "Click-" + String.valueOf(position), Toast.LENGTH_SHORT).show();
}
public static class EfficientAdapter extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private Bitmap mIcon1;
private Context context;
String strUrl;
InboxBean iBean;
InboxBean inboxBean;
XmlParser parser;
ArrayList<Object> result;
public EfficientAdapter(Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
this.context = context;
strUrl = "http://192.168.5.10/ijoomer_test/index.php?option=com_community&view=frontpage&task=inbox_xml&id="+ConstantData.user_id+"&sessionid="+ConstantData.session_id+"&tmpl=component";
parser = new XmlParser(strUrl, new InboxBean());
result = parser.ParseUrl("data", "message");
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.adapter_content, null);
holder = new ViewHolder();
holder.textLine = (TextView) convertView.findViewById(R.id.textLine);
holder.iconLine = (ImageView) convertView.findViewById(R.id.iconLine);
holder.txtBodyList = (TextView) convertView.findViewById(R.id.txtBodyList);
holder.txtPostDate = (TextView) convertView.findViewById(R.id.txtPostDate);
convertView.setOnClickListener(new OnClickListener() {
private int pos = position;
@Override
public void onClick(View v) {
Toast.makeText(context, "Click-" + String.valueOf(pos), Toast.LENGTH_SHORT).show();
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.iconLine.setImageBitmap(mIcon1);
// holder.textLine.setText("flag " + String.valueOf(position));
for(int i=0; i<result.size(); ++i)
{
iBean = (InboxBean)result.get(i);
holder.textLine.setText(iBean.subject);
holder.txtBodyList.setText(iBean.body);
Log.d("Position", ""+iBean);
Log.d("Position", ""+iBean.subject);
holder.txtPostDate.setText(iBean.postdate);
}
return convertView;
}
static class ViewHolder {
TextView textLine;
ImageView iconLine;
// Button buttonLine;
TextView txtBodyList;
TextView txtPostDate;
}
@Override
public Filter getFilter() {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@ Override
public int getCount() {
// TODO Auto-generated method stub
Log.d("Counter", ""+result.size());
return result.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return 0;
}
}
}
在上面的代码中,我从webservice获取记录。问题是总共有12条记录,我得到了12条记录但是每行最后一条记录都打印出来请给我解决方案
答案 0 :(得分:1)
你在你的适配器类中有循环...根本不需要...如果你想为文本框分配值,那么只需要执行一次..删除循环...