android选择控件



package kd.scan;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.hardware.barcode.Scanner;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import kd.scan.msgbox;
import kd.scan.stockbusi.assetcheck.MyadapterBarcode;
 

public class baseinfolookup extends Activity {
 public Handler handler;
    public Handler sqlhandler;
    public sqlhelper sqlhelp;
    public myapplication sqlapp;
    msgbox showmsg=null;
    public String strUUID;
   
    DisplayMetrics dm = new DisplayMetrics();
   
    
    private MediaPlayer mediaPlayer,mediaPlayerErr;
  private boolean playBeep;
  private static final float BEEP_VOLUME = 0.10f;//控制音量大小
  private boolean vibrate;
  private boolean go;
    
 private int kk;
 private int jj;
private int intBeepCount;//qk 响声的次数
private boolean blnIsBusy;//标记是否查询完,没有不进行下一次查询
    
  
 
private String strUserID;
private String strUserName;

long lngSeconds=0;
private boolean blnSaved=false;
private ListView baseinfolookup_lv_l1;
private EditText baseinfolookup_et_filter;
private Intent calltt;//调用的Intent  
private int baseinfotype;
private MyadapterBarcode ada;
private Button baseinfolookup_bt_search;
private TextView baseinfolookup_tv_tip;
//客户,部门,职员,物料,仓库,仓位,单位,供应商,提货方式,盘点方案;
private float[][] fColWidth=new float[][]{
  {2,14,2,4,0,0,0,0,0,0}//客户
  ,{4,12,2,4,0,0,0,0,0,0}//部门
  ,{2,6,4,10,3,3,3,0,0,0}//职员
        ,{4,8,4,4,3,0,0,0,0,0}//物料
        ,{2,14,2,4,0,0,0,0,0,0}//仓库
        ,{5,6,4,4,3,3,3,0,0,0}//仓位
        ,{2,14,2,4,0,0,0,0,0,0}//单位
        ,{2,14,2,4,0,0,0,0,0,0}//供应商
        ,{2,14,2,4,0,0,0,0,0,0}//提货方式
        ,{2,14,2,4,0,0,0,0,0,0}//盘点方案
        };

protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  Window window;
  window = getWindow();
   requestWindowFeature(Window.FEATURE_NO_TITLE); 
   window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                  WindowManager.LayoutParams.FLAG_FULLSCREEN); 
   window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//屏幕常亮
   getWindowManager().getDefaultDisplay().getMetrics(dm);
  showmsg=new msgbox(this);
  
  setContentView(R.layout.baseinfolookup );
  baseinfolookup_bt_search=(Button)findViewById(R.id.baseinfolookup_bt_search);
  baseinfolookup_tv_tip=(TextView)findViewById(R.id.baseinfolookup_tv_tip);
  baseinfolookup_lv_l1=(ListView)findViewById(R.id.baseinfolookup_lv_l1);
  baseinfolookup_et_filter=(EditText)findViewById(R.id.baseinfolookup_et_filter);
  baseinfolookup_lv_l1.setOnItemClickListener(
    new OnItemClickListener()
    {
     public void onItemClick(AdapterView<?> arg0,View arg1,int arg2,long arg3)
     {
      LinearLayout myll=(LinearLayout)arg1;
     String  retrunitemid=((TextView)myll.getChildAt(0)).getText().toString();
     if(!retrunitemid.equals("")){
      ada.SelectRow=Integer.parseInt( retrunitemid);
     
     // ada.notifyDataSetChanged();
        }else{
         ada.SelectRow=-1;
        }
     //返回数据
     ReturnData(ada.SelectRow-1);
     }
    }
    );
  //t=(Control_Table)findViewById(R.id.t);
//  t.SetOnSelectRow(new Control_Table_Listener(){
//
//   @Override
//   public void onSelectRow(int Row) {
//    // TODO Auto-generated method stub
//    showmsg.dialog_toast(String.valueOf(Row));
//   }});
  
 
  handler=new Handler()
  {
    
    public void handleMessage(Message msg)
         {
     try{
          switch(msg.what )
          {
          case Scanner.BARCODE_READ: {
          playBeepSoundAndVibrate();
          String strtext=(String)msg.obj;
          strtext=strtext.replace("'", "");//源头防注入
         
             break;
          }
          case 2://savebill返回
           blnIsBusy=false;
           showWait(false,"");
           String[] strData1;
           strData1=msg.getData().getStringArray("strData");
        
           if(strData1[1].equals("-1") | strData1[1].equals("-999"))
           {
               showmsg.dialog_yes_only("异常", strData1[2], "");
           }
           else
           {
        
           }
           break;
          case 0: //select 返回数据
           blnIsBusy=false;
           showWait(false,"");
           String[] strData;
           strData=msg.getData().getStringArray("strData");
           if(strData[1].equals("-1") | strData[1].equals("-999"))
           {
               showmsg.dialog_yes_only("异常", strData[2], "");
           }
           else
           {
             if(1==msg.arg1){// 基础资料查询返回
             showData4(strData);
              strData=null;
           
            }
         
           }
           break;
          case 1:
           Long rows;
           String errmsg;
             rows=msg.getData().getLong("returnRows");
             errmsg=msg.getData().getString("errmsg");
             if(rows==-1)
             {
              Log.d("qqkk","error-1:"+errmsg);
             }else if(rows==-999){
              Log.d("qqkk","error-999:"+errmsg);
             
             }
             else
             {
              Log.d("qqkk","OK:"+rows.toString());
             }
          
           break;
         
          }
          }catch(Exception ex)
          {
           showmsg.dialog_yes_only("异常", ex.getMessage(), "");
          }
         // process incoming messages here
         }
  };
  calltt=getIntent();
  baseinfotype=calltt.getIntExtra("itemclassid", 0);//获取基础资料类型ID
   
  sqlapp=(myapplication)getApplicationContext();
  strUUID=sqlapp.strUUID;
  sqlhelp=sqlapp.sqlhelp;//全局变量保存数据库操作线程
  sqlhelp.superHd=handler;  
  
  
  strUserID=sqlapp.strUserID;
  strUserName=sqlapp.strUserName;
  //测试时,暂用管理员
   if(strUserID.equals("0")){//16394 Administrator
    strUserID="16394";
    strUserName="Administrator";
   }

 
 }
//返回数据
private void ReturnData(int row){
 String strFieldName="";
 String strFieldValue="";
 String strReturnCode="";
 if(row>=0){
  strReturnCode="1";//表示有数据返回
  for(int i=0;i<ada._ds.ColCount();i++){
   if(strFieldName.equals("")){
    strFieldName=ada._ds.GetFieldName(i);
   }else{
    strFieldName=strFieldName+"/"+ada._ds.GetFieldName(i);;
   }
   if(strFieldValue.equals("")){
    strFieldValue=ada._ds.GetValue(row, i);
   }else{
    strFieldValue=strFieldValue+"/"+ada._ds.GetValue(row, i).trim();//去左右空格
   }
  }
 }else{
  strReturnCode="0";
 }
 calltt.putExtra("strReturnCode", strReturnCode);//
 calltt.putExtra("strFieldName", strFieldName);//
 calltt.putExtra("strFieldValue", strFieldValue);//
 
  setResult(10, calltt);  //10表示基础资料选择返回
  finish();
}
 private void showData4(String[] strData){
   try{
   String strBarcode="";
    
 //=----------------------------------------------
   List<String>   ll=new ArrayList<String>();
   DataSet _ds=new DataSet();
   _ds.SetDataSource(strData);
   
   if(_ds.RowCount()==0){
    baseinfolookup_tv_tip.setText("0条数据");
    if(ada!=null){
     ada.SelectRow=0;
     ada._ds.RemoveAll();
     ada.refrushGrid();
    }
    return;
   }
     if(ada==null){
      ada=new MyadapterBarcode(this, strData,dm.widthPixels);
    //设置列宽
      ada.setColWidth(fColWidth[baseinfotype]);
      baseinfolookup_lv_l1.setAdapter(ada);
      baseinfolookup_tv_tip.setText(String.valueOf(_ds.RowCount())+"条数据");
      ada.refrushGrid();  
    }else{//存在就是覆盖数据
             ada._ds.RemoveAll();
             ada.AddData(strData);
             baseinfolookup_tv_tip.setText(String.valueOf(_ds.RowCount())+"条数据");
    ada.refrushGrid();
     return;
     }
        
  
  
   }catch(Exception e){
    showmsg.dialog_yes_only("异常","showdata4:"+e.getMessage(), "");
   }
}
 public void baseinfolookup_bt_search_click(View v){
  String strFilter="";
  String strSQL="";
  strFilter=baseinfolookup_et_filter.getText().toString().replace("'", "");
  strSQL="exec qk_getBaseInfo "+baseinfotype+",'"+strFilter+"'";
  showWait(true,"");
  SendSQLHandler(strSQL,0,1);
 }
  //显示或者隐藏进度条
  private void showWait(boolean blnShow,String strmsg){
   if(blnShow){
    baseinfolookup_bt_search.setEnabled(false);
    baseinfolookup_bt_search.setText("数据查询中...");
    //assetcheckwait.setVisibility(View.VISIBLE);
   // assetchecktvwaitmsg.setVisibility(View.VISIBLE);
  //  assetchecktvwaitmsg.setText(strmsg);
   }else{
    baseinfolookup_bt_search.setEnabled(true);
    baseinfolookup_bt_search.setText("查找");
   // assetcheckwait.setVisibility(View.INVISIBLE);
   // assetchecktvwaitmsg.setVisibility(View.INVISIBLE);
  //  assetchecktvwaitmsg.setText("");
   }
  }
  private void SendSQLHandler(String strSQL,int intWhat,int intarg1)
    {
       try{
        if(!blnIsBusy){
         blnIsBusy=true;
       Message msg=sqlhelp.myhandler.obtainMessage();
        Bundle  data=new Bundle();
//           strSQL="select isnull(a.fitemid,'')+' '   fstockid,isnull(a.fname,'')+' '  fstockname,isnull(a.fnumber,'')+' '  fstocknumber,isnull(b.fspid,'')+' '  fstockplaceid,isnull(b.fname,'') +' ' fstockplacename,isnull(b.ffullnumber,'') +' '  fstockplacenumber  "
//             + "  from t_stock  a left join t_stockplace b on a.fspgroupid=b.fspgroupid  "
//             +"  where a.fdeleted=0 and b.fdeleted=0   and a.fnumber='"+strStockNo+"'  and  b.ffullnumber='"+strStockPlaceNo+"'";
         data.putString("strSQL", strSQL);
        
           data.putString("strYear", strUUID);
        msg.setData(data);
           msg.what =intWhat;
           msg.arg1=intarg1;//通过arg1来区分是哪个函数调用的
           sqlhelp.myhandler.sendMessage(msg);
           }
       }catch(Exception ex){
       showmsg.dialog_yes_only("异常", "SendSQLHandler:"+ex.getMessage(), "");
       }
    }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
   // TODO Auto-generated method stub
   
    if(keyCode==KeyEvent.KEYCODE_BACK)
    {     
     ReturnData(-1);
    }
   
   return super.onKeyDown(keyCode, event);
  }
 private void initBeepSound() {
  if (playBeep && mediaPlayer == null) {
   // The volume on STREAM_SYSTEM is not adjustable, and users found it
   // too loud,
   // so we now play on the music stream.
   setVolumeControlStream(AudioManager.STREAM_MUSIC);
   mediaPlayer = new MediaPlayer();
   mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
   mediaPlayer.setOnCompletionListener(beepListener);

//   AssetFileDescriptor file = getResources().openRawResourceFd(
//     R.raw.beep);
   AssetFileDescriptor file = getResources().openRawResourceFd(
     R.raw.beep);
   try {
    mediaPlayer.setDataSource(file.getFileDescriptor(),
      file.getStartOffset(), file.getLength());
    file.close();
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
   
    mediaPlayer.prepare();
   } catch (IOException e) {
    mediaPlayer = null;
   }
  }
 }
 private void initBeepSoundErr() {
  if (playBeep && mediaPlayerErr == null) {
   // The volume on STREAM_SYSTEM is not adjustable, and users found it
   // too loud,
   // so we now play on the music stream.
   setVolumeControlStream(AudioManager.STREAM_MUSIC);
   mediaPlayerErr = new MediaPlayer();
   mediaPlayerErr.setAudioStreamType(AudioManager.STREAM_MUSIC);
   mediaPlayerErr.setOnCompletionListener(beepListener);

//   AssetFileDescriptor file = getResources().openRawResourceFd(
//     R.raw.beep);
   AssetFileDescriptor file = getResources().openRawResourceFd(
     R.raw.err1);
   try {
    mediaPlayerErr.setDataSource(file.getFileDescriptor(),
      file.getStartOffset(), file.getLength());
    file.close();
    mediaPlayerErr.setVolume(BEEP_VOLUME, BEEP_VOLUME);
   
    mediaPlayerErr.prepare();
   } catch (IOException e) {
    mediaPlayerErr = null;
   }
  }
 }
 private static final long VIBRATE_DURATION = 200L;//震动时间  qk
 
 private void playBeepSoundAndVibrate() {
  if (playBeep && mediaPlayer != null) {
   mediaPlayer.start();
   
  }
  if (vibrate) {
   Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
   vibrator.vibrate(VIBRATE_DURATION);
  }
 }
 private void playBeepSoundAndVibrateErr() {
  if (playBeep && mediaPlayerErr != null) {
   mediaPlayerErr.start();
   
  }
  if (vibrate) {
   Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
   vibrator.vibrate(VIBRATE_DURATION);
  }
 }
 
 /**
  * When the beep has finished playing, rewind to queue up another one.
  */
 private final OnCompletionListener beepListener = new OnCompletionListener() {
  public void onCompletion(MediaPlayer mediaPlayer) {
   mediaPlayer.seekTo(0);
    if(intBeepCount>0)
    {
    mediaPlayer.start();//qk  连续响几次
    intBeepCount--;
    }
   
  }
 };
 //数据适配器
 public class MyadapterBarcode extends BaseAdapter{

  /* (non-Javadoc)
   * @see android.widget.Adapter#getCount()
   */
      private LayoutInflater mInflater;
  private DataSet _ds=new DataSet();
  private int  _ScreenWidth;
  private int  _unitWidth;
  private double dblSum=0;
  private double dblSelectSum=0;//选中行数的数量合计
  private int    intSelectRows=0;//选中行数
  private int   intBoxCount=0;//箱数
  public int SelectRow; //当前行
  private  String strBZcodelist="",strtempcode="";
  private int _colCount=10;//最多10列
  private float[] _colWidth=new float[_colCount];//列宽
  
   DecimalFormat a = new DecimalFormat("#,##0.00");
   Context _context;
  public MyadapterBarcode(Context context,String[] strdata,int intScreenWidth)
  {
   
   _ds.SetDataSource(strdata);
   _ScreenWidth=intScreenWidth;
   _unitWidth=_ScreenWidth/20;//均分20个单位
   
    mInflater = LayoutInflater.from(context);
    //求数列合计
    intBoxCount=0;strtempcode="";strBZcodelist="";
//    for(int i=0;i<_ds.RowCount();i++){
//    // dblSum=dblSum+Double.parseDouble(_ds.GetValue(i, "数量"));
//     strtempcode= _ds.GetValue(i, "包装条码");
//     if(strBZcodelist.indexOf(strtempcode)<=0){
//      strBZcodelist=strBZcodelist+"/"+strtempcode;
//      intBoxCount++;
//     }
//    
//    }
  
  }
  public void setColWidth(float[] colwidth){
   for(int i=0;i<_colCount;i++){
    _colWidth[i]=colwidth[i];
   }
  }
  public String getValue(int row,String strFieldname)
  {
   return _ds.GetValue(row, strFieldname).replace("'", "");
  }
  public void setValue(int row,String strFieldname,String strValue){
   _ds.SetValue(row, strFieldname, strValue.replace("'", ""));
  
  }
  public void refrushGrid(){
   dblSum=0;intSelectRows=0;dblSelectSum=0;//修改值后,合计要选中数量要重算
   //2015-05-14  给仓库演示后,仓库希望加箱数,扫一次就一箱
    intBoxCount=0;strtempcode="";strBZcodelist="";
  
   
   notifyDataSetChanged();
  }
  //删除选中的行
  public void DelData()
  {
   _ds.DelSelectRow("fischoice");
  
  }
  public void AddData(String[] strdata){
   //往列表追加数据
   _ds.AddData(strdata);
   strdata=null;
   dblSum=0;
    intBoxCount=0;strtempcode="";strBZcodelist="";
   
     
   notifyDataSetChanged();
   
  }
  @Override
  public int getCount() {
   // TODO Auto-generated method stub
   return   _ds.RowCount()+1;//那个1是标题
  }

  /* (non-Javadoc)
   * @see android.widget.Adapter#getItem(int)
   */
  @Override
  public Object getItem(int position) {
   // TODO Auto-generated method stub
   return position;
  }

  /* (non-Javadoc)
   * @see android.widget.Adapter#getItemId(int)
   */
  @Override
  public long getItemId(int position) {
   // TODO Auto-generated method stub
   return position;
  }

 
 
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   //此种写法占用内存:数据滑到底占用内存:12.45,而且滑动很顺畅,不会卡
   // TODO Auto-generated method stub
   //显示一部分,就加载一部分,而不是全部加载
   // TODO Auto-generated method stub
   try{
   ViewHolder viewHolder = null;
        if (null == convertView)
        { viewHolder = new ViewHolder();
         convertView = mInflater.inflate(R.layout.baseinfolookup_row, null);
           
         //此处可调整列的位置
     viewHolder.cbox=(CheckBox) convertView.findViewById(R.id.baseinfolookup_row_cbox) ;viewHolder.cbox.setWidth((int) (_unitWidth*3));
     //viewHolder.tvNo=(TextView)convertView.findViewById(R.id.assetcheckstockcol0) ;viewHolder.tvNo.setWidth(_unitWidth);//行号
     viewHolder.tvcol[0]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col0);//viewHolder.tvcol[0].setWidth((int) (_colWidth[0]*_unitWidth));
     viewHolder.tvcol[1]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col1) ;//viewHolder.tvcol[1].setWidth(3*_unitWidth);
     viewHolder.tvcol[2]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col2) ;//viewHolder.tvcol[2].setWidth((int) (2*_unitWidth));
     viewHolder.tvcol[3]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col3) ;//viewHolder.tvcol[3].setWidth((int) (1.5*_unitWidth));
       viewHolder.tvcol[4]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col4) ;//viewHolder.tvcol[4].setWidth(2*_unitWidth);
       viewHolder.tvcol[5]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col5) ;//viewHolder.tvcol[5].setWidth(2*_unitWidth);
     viewHolder.tvcol[6]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col6) ;//viewHolder.tvcol[6].setWidth(3*_unitWidth);
     viewHolder.tvcol[7]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col7) ;//viewHolder.tvcol[7].setWidth(3*_unitWidth);
      viewHolder.tvcol[8]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col8) ;//viewHolder.tvcol[8].setWidth(2*_unitWidth);
       viewHolder.tvcol[9]=(TextView)convertView.findViewById(R.id.baseinfolookup_row_col9) ;//viewHolder.tvcol[9].setWidth(4*_unitWidth);
       for(int i=0;i<_colCount;i++){//设置列宽
       viewHolder.tvcol[i].setWidth((int) (_colWidth[i]*_unitWidth));
       if(_colWidth[i]==0){
        viewHolder.tvcol[i].setVisibility(View.INVISIBLE);
       }
       }
       viewHolder.cbox.setOnClickListener(new View.OnClickListener() {
      //因为是复选框,所以只要单击,状态一定改变,等同于oncheckedchange
      @Override
      public void onClick(View v) {
       // TODO Auto-generated method stub
       try{
       int intRow=-1;
       CheckBox cb=(CheckBox)v;
       intRow=Integer.parseInt(v.getTag().toString());
      // SelectRow=intRow;
           if(cb.isChecked()){
            if(intRow==0){//全选
             dblSelectSum=dblSum;
             intSelectRows=_ds.RowCount();
             for(int i=0;i<_ds.RowCount();i++){
              _ds.SetValue(i, "fischoice", "1");
             }
            }else{
            _ds.SetValue(intRow-1, "fischoice", "1");
           // dblSelectSum=dblSelectSum+Double.parseDouble(_ds.GetValue(intRow-1, "数量"));//选中行数的数量合计
               intSelectRows=intSelectRows+1;//选中行数
           //    setEditText4(intRow-1);//把选中行的数据显示在编辑页签
            }
           }else{
            if(intRow==0){
             for(int i=0;i<_ds.RowCount();i++){
              _ds.SetValue(i, "fischoice", "0");
             
             }
             dblSelectSum=0;//dblSelectSum-Double.parseDouble(subZeroAndDot(_ds.GetValue(intRow, 4)));//选中行数的数量合计
                intSelectRows=0;//选中行数
            }else{
            _ds.SetValue(intRow-1, "fischoice", "0");
          //  dblSelectSum=dblSelectSum-Double.parseDouble(_ds.GetValue(intRow-1, "数量"));//选中行数的数量合计
               intSelectRows=intSelectRows-1;//选中行数
             //  setEditText(intRow-1);//把选中行的数据显示在编辑页签
            }
           }
       notifyDataSetChanged();
       
      
       }catch(Exception e)
       {
        showmsg.dialog_yes_only("异常","getView:"+ e.getMessage(), "");
       }
      }
     });
      convertView.setTag(viewHolder);
        }else
        {
         viewHolder = (ViewHolder) convertView.getTag();
        }
  
    if(position==0){//标题
       viewHolder.cbox.setTag(position);viewHolder.cbox.setText("");// viewHolder.cbox.setChecked(false);
       for(int i=0;i<_ds.ColCount();i++){//减的这个1是fischoice
        viewHolder.tvcol[i].setText(_ds.GetFieldName(i));
        viewHolder.tvcol[i].setGravity(Gravity.CENTER);
       }
    }else{
     //tvcaption.setText(tvcaption.getText()+"  "+position);viewHolder.tvNumber.setGravity(Gravity.LEFT); //
     //重要日志:因为控件重用,所以在position==0中设置的控件的属性,在Position>0的时候因为用的是position==0时的控件,所以要重置属性!
      viewHolder.cbox.setTag(position); viewHolder.cbox.setText(String.valueOf(position)); viewHolder.cbox.setGravity(Gravity.CENTER);
     // viewHolder.tvNo.setText(String.valueOf(position));
      for(int i=0;i<_ds.ColCount();i++){
       viewHolder.tvcol[i].setText(_ds.GetValue(position-1, i));
       viewHolder.tvcol[i].setGravity(Gravity.CENTER);
      }
     if(_ds.GetValue(position-1, "fischoice").equals("1")){
      viewHolder.cbox.setChecked(true);
     }else
     {
      viewHolder.cbox.setChecked(false);
     }
    }
  
   if(  position%2==0 && position>0)
   {
    convertView.setBackgroundResource(R.color.rowodd);//奇数行标记
      
   }else if( position%2!=0 && position>0){
    convertView.setBackgroundResource(R.color.white);//奇数行标记
   }
   if(position>0 && position==SelectRow){
    convertView.setBackgroundResource(R.color.gold);//选中行标记
   }
      if(position==0){
       convertView.setBackgroundResource(R.color.gray);//
      }
//   
   }catch(Exception e)
   {
    showmsg.dialog_yes_only("异常","fillitem:"+ e.getMessage(), "");
   }
   return convertView;
   
  }
 
  private   class ViewHolder
     {
   CheckBox cbox;
      TextView[]  tvcol=new TextView[12];
   
     }
     
    }
}


--布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
      <EditText
       android:id="@+id/baseinfolookup_et_filter"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
 
       android:hint="过滤条件"
       android:singleLine="true"
       />
    <Button
        android:id="@+id/baseinfolookup_bt_search"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:layout_below="@id/baseinfolookup_et_filter"
        android:background="@drawable/buttonupanddown"
       android:onClick="baseinfolookup_bt_search_click"
        android:text="@string/baseinfolookup_search" />
    <TextView
        android:id="@+id/baseinfolookup_tv_tip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/baseinfolookup_bt_search"
        android:background="@color/gold"
        />
     <HorizontalScrollView
              android:id="@+id/baseinfolookup_hs_h1"
              android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_below="@id/baseinfolookup_tv_tip"
          android:fillViewport="true"
              >
    <ListView
        android:id="@+id/baseinfolookup_lv_l1"
         android:dividerHeight="1dp"
         android:divider="#FF909090"  
   
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:choiceMode="singleChoice"
        ></ListView>
    </HorizontalScrollView>     
</RelativeLayout>


--row

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
     <CheckBox
       android:id="@+id/baseinfolookup_row_cbox"
       android:layout_width="wrap_content"
       android:layout_height="20dp"
    android:focusable="false"
    android:textSize="10sp"
  
       />  
              <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
        <TextView
        android:id="@+id/baseinfolookup_row_col0"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:textSize="10sp"
            android:text=""
         />
       <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
         <TextView
        android:id="@+id/baseinfolookup_row_col1"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
              android:textSize="10sp"
         />
       <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
     <TextView
        android:id="@+id/baseinfolookup_row_col2"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />

     <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
      <TextView
        android:id="@+id/baseinfolookup_row_col3"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />
     <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
      <TextView
        android:id="@+id/baseinfolookup_row_col4"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />
 
          <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
       <TextView
        android:id="@+id/baseinfolookup_row_col5"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />
     <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
      <TextView
        android:id="@+id/baseinfolookup_row_col6"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />
 
 
     <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
       <TextView
        android:id="@+id/baseinfolookup_row_col7"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />
  <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
       <TextView
        android:id="@+id/baseinfolookup_row_col8"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="10sp"
         />
 
         
             <View
             android:layout_width="1dp"
             android:background="@color/blue"
             android:layout_height="fill_parent"/>
       <TextView
        android:id="@+id/baseinfolookup_row_col9"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
             android:textSize="10sp"
         />
       
    
      
     
      
</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值