龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 移动开发 > Android开发 >

Android中使用ListView实现漂亮的表格效果(5)

时间:2014-10-11 03:06来源:网络整理 作者:网络 点击:
分享到:
import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.os.Bundle; import android.preference.PreferenceMana

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TableRow;
import android.widget.TextView;

public class StockListActivity extends Activity {

 private static final String TAG = "com.android.msoft.mfinance.ui.StockListActivity";
 private SharedPreferences mPreference;
 private TextView mCodeTextView;
 private TextView mSymbolTextView;
 private TextView mLastPriceTextView;
 private TextView mPriceChangeTextView;
 private TextView mPriceChangePercentageTextView;
 private ListView mStockListView;
 private TableRow mStockListHeader;
 private float mTextSize;

 private int mBgColor;
 private int mDownTextColor;
 private int mUpTextColor;
 private Cursor mStockListCursor;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.stock_list);

  mPreference = PreferenceManager.getDefaultSharedPreferences(this);

  refreshDisplayPreference();

  mStockListHeader = (TableRow) findViewById(R.id.stock_list_header_row);
  mCodeTextView = (TextView) findViewById(R.id.stock_list_header_code);
  mSymbolTextView = (TextView) findViewById(R.id.stock_list_header_symbol);
  mLastPriceTextView = (TextView) findViewById(R.id.stock_list_header_last_price);
  mPriceChangeTextView = (TextView) findViewById(R.id.stock_list_header_price_change);
  mPriceChangePercentageTextView = (TextView) findViewById(R.id.stock_list_header_price_change_percentage);

  mStockListView = (ListView) findViewById(R.id.stock_list_view);

  refreshStockListHeader();

  mStockListCursor = getContentResolver().query(
    Stock.CONTENT_URI_STOCK_WITH_MARKET, null, null, null,
    StockMarketColumns.CHANGE_PRICE_PERCENT + " DESC");

  StockListAdapter listViewAdpater = new StockListAdapter(this,
    mStockListCursor);
  mStockListView.setAdapter(listViewAdpater);
 }

 @Override
 protected void onDestroy() {
  if (!mStockListCursor.isClosed()) {
   mStockListCursor.close();
  }

  super.onDestroy();
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {

  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.stock_list_option_menu, menu);
  return super.onCreateOptionsMenu(menu);
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  case R.id.stock_list_option_menu_settings:
   Intent intent = new Intent(this, MFinancePreferenceActivity.class);
   startActivity(intent);
   break;
  }

  return super.onOptionsItemSelected(item);
 }

 private void refreshDisplayPreference() {

  UpDownColor upAndDownColor = MFinancePreferenceActivity.UpDownColor
    .valueOf(mPreference.getString("up_down_color", "RED_GREEN"));

精彩图集

赞助商链接