2011-04-08 40 views
0
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; 
     } 
    } 
} 

在上面的代碼中,我從Web服務獲取記錄。問題是,總共有12條記錄,我得到12條記錄,但在每行最後一條記錄是打印請給我解決方案自定義列表視圖中的問題

+0

您正在從Web服務接收12條記錄。最後一個記錄是打印。我無法把你帶到這裏......你是否在最後一行的所有欄中都有「印刷品」? – 2011-04-08 04:13:05

+0

我得到12行相同的數據(最後一條記錄).... – shripal 2011-04-08 04:14:44

回答

1

你有for循環在你的適配器類......這根本不需要。 ...如果你想分配值的文本框,然後只做一次...取消循環...

+0

你老闆......我知道了..... – shripal 2011-04-08 04:52:28