public void loadData() { // 查询数据 showDialog(0); final AbHttpItem item = new AbHttpItem(); item.callback = new AbHttpCallback() { @Override public void update() { removeDialog(0); if (mStockList != null && mStockList.size() > 0) { contents.clear(); Stock mStock = null; for (int i = 0; i < mStockList.size(); i++) { mStock = mStockList.get(i); String[] data1 = new String[] { mStock.id, mStock.text1, mStock.text2, mStock.text3, mStock.text4 }; contents.add(data1); } tableAdapter.notifyDataSetChanged(); } else { contentLayout.removeAllViews(); contentLayout.addView(noView, layoutParamsFF); } } @Override public void get() { try { mStockList = new ArrayList<Stock>(); Stock mStock1 = null; for (int i = 0; i < 20; i++) { mStock1 = new Stock(); mStock1.setId(String.valueOf(i)); mStock1.setText1("Text1"); mStock1.setText2("Text2"); mStock1.setText3(String.valueOf(R.drawable.logo_418)); mStock1.setText4("Text4"); mStock1.setText5("Text5"); mStockList.add(mStock1); } } catch (Exception e) { e.printStackTrace(); showToastInThread(e.getMessage()); } }; }; mAbHttpPool.download(item); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); application = (MyApplication) abApplication; setAbContentView(mInflater.inflate(R.layout.table_data_list, null)); setTitleText(R.string.table_list_name); setLogo(R.drawable.button_selector_back); this.setTitleLayoutBackground(R.drawable.top_bg); this.setTitleTextMargin(10, 0, 0, 0); this.setLogoLine(R.drawable.line); logoView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); noView = LayoutInflater.from(this).inflate(R.layout.no_data, null); mAbHttpPool = AbHttpPool.getInstance(); // (1)标题配置 titles = new String[] {"标题1", "标题2", "标题3", "图标", "标题4"}; // (2)内容列表配置 contents = new ArrayList<String[]>(); // (3)列类型配置 cellTypes = new int[] { AbCellType.STRING, AbCellType.STRING, AbCellType.STRING, AbCellType.IMAGE, AbCellType.STRING }; // (4)列宽配置(%) 超过100% 可以横向滑动 cellWidth = new int[] {25, 25, 25, 25, 25}; // (5)行高(索引0:标题高,1:内容列表高) rowHeight = new int[] {45, 45}; // (6)行文字大小(索引0标题,1内容列表) rowTextSize = new int[] {15, 12}; // (7)行文字颜色(索引0标题,1内容列表) rowTextColor = new int[] {Color.rgb(255, 255, 255), Color.rgb(113, 113, 113)}; // (8)背景资源 tableResource = new int[] { android.R.color.transparent, R.drawable.title_cell, android.R.color.transparent, R.drawable.content_cell }; // (9)表格实体 table = AbTable.newAbTable(this, 5); table.setTitles(titles); table.setContents(contents); table.setCellTypes(cellTypes); table.setCellWidth(cellWidth); table.setRowHeight(rowHeight); table.setRowTextSize(rowTextSize); table.setTableResource(tableResource); table.setRowTextColor(rowTextColor); // 点击事件 AbOnItemClickListener mAbOnItemClickListener = new AbOnItemClickListener() { @Override public void onClick(int position) { showToast("点击了第" + position + "行的图标"); } }; table.setItemCellTouchListener(mAbOnItemClickListener); // (10)TableAdapter对象 tableAdapter = new AbTableArrayAdapter(TableDataListActivity1.this, table); // (12)ListView mListView = (ListView) findViewById(R.id.mListView); // (11)设置Adapter mListView.setAdapter(tableAdapter); // -------------- 表格控件-------end------------------ // 点击事件 mListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {} }); loadData(); }