ListView优化

/**
  *
  * 博雅商城使用
  */
 private class MyListViewAdapter extends BaseAdapter {

  private LayoutInflater mLayoutInflater;

  public MyListViewAdapter(Context context) {
   this.mLayoutInflater = LayoutInflater.from(context);
  }

  @Override
  public int getCount() {
   return dataList.size();
  }

  @Override
  public Object getItem(int position) {
   return null;
  }

  @Override
  public long getItemId(int position) {
   // TODO Auto-generated method stub
   return 0;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   ViewHolder holder = null;
   if (convertView == null) {
    holder = new ViewHolder();
    convertView = mLayoutInflater.inflate(R.layout.tools_row, null);
    convertView.setBackgroundResource(R.drawable.dtht_1);
    if (RoomBitmapIds.getTypeface() == null) {
     RoomBitmapIds.initTypeface(mActivity); // 初始化字体
    }
    Typeface tf = RoomBitmapIds.getTypeface();
    holder.icon = (ImageView) convertView.findViewById(R.id.icon);

    holder.jz = (TextView) convertView.findViewById(R.id.jz);
    holder.jz.setTypeface(tf);
    holder.jg = (TextView) convertView.findViewById(R.id.jg);
    holder.jg.setTypeface(tf);
    holder.buy = (RelativeLayout) convertView
      .findViewById(R.id.buy);

    convertView.setTag(holder);
   } else {
    holder = (ViewHolder) convertView.getTag();
   }
   System.out.println((String) dataList.get(position).get(
     "productIcon"));
   holder.icon.setBackgroundResource(Market.icons
     .get((String) dataList.get(position).get("productIcon")));
   holder.jz.setText((String) dataList.get(position)
     .get("productName"));
   int bj = Integer.parseInt(String.valueOf(dataList.get(position)
     .get("productBj")));
   if (bj != 0) {
    holder.jg.setText(bj + "博雅币");
   } else {
    holder.jg.setText(String.valueOf(dataList.get(position).get(
      "productYj"))
      + "游戏币");
   }
   return convertView;
  }

 }

 /**
  *
  * 博雅商城使用
  */
 public final class ViewHolder {
  public ImageView icon;
  TextView jz;
  TextView jg;
  RelativeLayout buy;
 }

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal" android:layout_width="fill_parent"
 android:layout_height="40dip">
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:background="@drawable/storecell_bg">
  <!-- 头片 -->
  <ImageView android:id="@+id/icon" android:layout_width="40dip"
   android:layout_height="40dip" android:layout_alignParentLeft="true"
   android:layout_marginLeft="10dip" android:gravity="center"
   android:background="@drawable/vip_cash"
   android:layout_centerVertical="true" />
  <!-- 价值 -->
  <TextView android:id="@+id/jz" android:layout_width="wrap_content"
   android:layout_height="20dip" android:layout_toRightOf="@id/icon"
   android:layout_alignTop="@id/num" android:textColor="#000000"
   android:textStyle="bold" android:gravity="left" />
  <!-- 价格 -->
  <TextView android:id="@+id/jg" android:layout_width="wrap_content"
   android:layout_height="20dip" android:layout_toRightOf="@id/icon"
   android:layout_below="@id/jz" android:textColor="#555555"
   android:gravity="left" />
  <!-- 购买 -->
  <RelativeLayout android:id="@+id/buy"
   android:layout_width="wrap_content" android:layout_height="wrap_content"
   android:gravity="center" android:layout_alignParentRight="true"
   android:layout_marginRight="10dip" android:background="@drawable/vip_btn"
   android:layout_centerVertical="true">
   <TextView android:text="@string/buy" android:textColor="#ffffff"
    android:textSize="16sp" android:layout_width="wrap_content"
    android:paddingBottom="5dip" android:layout_height="wrap_content"
    android:gravity="center" android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
  </RelativeLayout>


 </RelativeLayout>
</LinearLayout>

你可能感兴趣的:(游戏,android,xml)