public void appendNeighborCellInfo(NeighboringCellInfo data) {

    TableRow tr = new TableRow(this);
    int color = Color.parseColor("#000000");
    TextView label = new TextView(this);
    TableRow.LayoutParams params = new TableRow.LayoutParams();
    params.span = 2;
    params.leftMargin = 10;
    params.rightMargin = 10;
    params.bottomMargin = 10;

    TableRow.LayoutParams params2 = new TableRow.LayoutParams();
    params2.weight = 1;
    // params2.gravity=16;

    label.setLayoutParams(params);
    label.setText("Neighbor Cell Tower");
    label.setTextSize(20);
    label.setTextColor(Color.parseColor("#909090"));
    // label.setTypeface(null, Typeface.BOLD);
    // label.setGravity(Gravity.CENTER);
    // label.setPadding(0, 10, 0, 0);
    tr.addView(label);
    tr.setLayoutParams(params);

    ((TableLayout) findViewById(R.id.info_table)).addView(tr, params);

    tr = new TableRow(this);

    label = new TextView(this);
    label.setLayoutParams(params);
    label.setText("Network type ");
    label.setTextSize(18);
    label.setTextColor(color);

    tr.setBackgroundResource(R.drawable.black_alpha);
    tr.addView(label);

    label = new TextView(this);
    label.setTextSize(18);
    label.setLayoutParams(params2);
    label.setText(getString(DCSConvertorUtil.networkTypeToStringId(data.getNetworkType())));
    label.setTextColor(color);
    tr.addView(label);

    ((TableLayout) findViewById(R.id.info_table)).addView(tr, params);
    tr.setLayoutParams(params);

    tr = new TableRow(this);
    label = new TextView(this);
    label.setTextSize(18);
    label.setTextColor(color);
    tr.setBackgroundResource(R.drawable.black_alpha);
    label.setLayoutParams(params);
    label.setText("PSC ");
    tr.addView(label);

    label = new TextView(this);
    label.setText(data.getPsc() + "");
    label.setLayoutParams(params2);
    label.setTextColor(color);
    tr.addView(label);
    ((TableLayout) findViewById(R.id.info_table)).addView(tr, params);

    tr.setLayoutParams(params);

    tr = new TableRow(this);
    label = new TextView(this);
    label.setLayoutParams(params);
    label.setText("Cell id ");
    label.setTextSize(18);
    label.setTextColor(color);
    tr.setBackgroundResource(R.drawable.black_alpha);
    tr.addView(label);

    label = new TextView(this);
    label.setLayoutParams(params);
    label.setText(data.getCid() + "");
    label.setTextColor(color);
    label.setLayoutParams(params2);
    tr.addView(label);
    ((TableLayout) findViewById(R.id.info_table)).addView(tr, params);
    tr.setLayoutParams(params);

    tr = new TableRow(this);
    label = new TextView(this);
    label.setLayoutParams(params);
    label.setText("Area code ");
    label.setTextSize(18);
    label.setTextColor(color);
    tr.setBackgroundResource(R.drawable.black_alpha);
    tr.addView(label);

    label = new TextView(this);
    label.setText(data.getLac() + "");
    label.setTextColor(color);
    label.setLayoutParams(params2);
    tr.addView(label);
    ((TableLayout) findViewById(R.id.info_table)).addView(tr, params);
    tr.setLayoutParams(params);

    tr = new TableRow(this);
    label = new TextView(this);
    label.setLayoutParams(params);
    label.setText("Signal Strength ");
    label.setTextSize(18);
    label.setTextColor(color);
    tr.setBackgroundResource(R.drawable.black_alpha);
    tr.addView(label);

    label = new TextView(this);
    label.setLayoutParams(params);
    label.setText(data.getRssi() + "");
    label.setTextColor(color);
    label.setLayoutParams(params2);
    tr.addView(label);
    ((TableLayout) findViewById(R.id.info_table)).addView(tr, params);
    tr.setLayoutParams(params);
  }
Ejemplo n.º 2
0
  private void createDataTable() {
    sqlite.openConnection();
    ArrayList<Grafica> candidatos = sqlite.getCandidatos();
    sqlite.closeConnection();

    //
    TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams();
    tableRowParams.setMargins(5, 3, 5, 3);
    tableRowParams.weight = 1;
    // encabezado
    TableRow rowHead = new TableRow(this);
    rowHead.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    // col 1
    TextView col1 = new TextView(this);
    col1.setBackgroundResource(R.drawable.tv_bg);
    col1.setGravity(Gravity.CENTER);
    col1.setTypeface(null, Typeface.BOLD);
    col1.setTextSize(12);
    col1.setPadding(6, 10, 6, 10);
    col1.setText("TEMA");
    // col 2
    TextView col2 = new TextView(this);
    col2.setBackgroundResource(R.drawable.tv_bg);
    col2.setGravity(Gravity.CENTER);
    col2.setTypeface(null, Typeface.BOLD);
    col2.setTextSize(12);
    col2.setPadding(6, 10, 6, 10);
    col2.setText("LECCIÓN");
    // col 3
    TextView col3 = new TextView(this);
    col3.setBackgroundResource(R.drawable.tv_bg);
    col3.setGravity(Gravity.CENTER);
    col3.setTypeface(null, Typeface.BOLD);
    col3.setTextSize(12);
    col3.setPadding(6, 10, 6, 10);
    col3.setText("CALF");
    // añade columnas
    rowHead.addView(col1, tableRowParams);
    rowHead.addView(col2, tableRowParams);
    rowHead.addView(col3, tableRowParams);
    // añade fila
    table_layout.addView(rowHead);
    for (Grafica c : candidatos) {
      TableRow row = new TableRow(this);
      row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

      // col 1
      TextView tv1 = new TextView(this);
      tv1.setBackgroundResource(R.drawable.tv_bg);
      tv1.setGravity(Gravity.CENTER);
      tv1.setTypeface(null, Typeface.BOLD);
      tv1.setTextSize(12);
      tv1.setPadding(6, 10, 6, 10);
      tv1.setText(c.getSigla());
      // col 2
      TextView tv2 = new TextView(this);
      tv2.setBackgroundResource(R.drawable.tv_bg);
      tv2.setGravity(Gravity.CENTER);
      tv2.setTextSize(12);
      tv2.setPadding(6, 10, 6, 10);
      tv2.setText(c.getNombre());
      // col 3
      TextView tv3 = new TextView(this);
      tv3.setBackgroundResource(R.drawable.tv_bg);
      tv3.setGravity(Gravity.CENTER);
      tv3.setTextSize(12);
      tv3.setPadding(6, 10, 6, 10);
      tv3.setText(String.valueOf(c.getVotos()));
      // añade columnas
      row.addView(tv1, tableRowParams);
      row.addView(tv2, tableRowParams);
      row.addView(tv3, tableRowParams);
      // añade fila
      table_layout.addView(row);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contact_country_legislator_layout);

    LegislatorDB helper = new LegislatorDB(this);
    final SQLiteDatabase db = helper.getReadableDatabase();

    // 查詢不分區立委名單
    Cursor c =
        db.query(
            "LEGISLATOR_DATA",
            new String[] {"legislator_id", "legislator_name"},
            "legislator_dist_id>2300",
            null,
            null,
            null,
            null);
    c.moveToFirst();

    int colCount = 3;
    int dataCount = c.getCount();
    int showedCount = 0;
    int reminder = dataCount % colCount;
    int rowCount = 0;

    if (reminder == 0) rowCount = dataCount / colCount;
    else rowCount = ((dataCount - reminder) / colCount) + 1;

    // 建立委員按鍵清單
    TableLayout layout = (TableLayout) findViewById(R.id.tableLegislatorList);
    for (int rowS = 0; rowS < rowCount; rowS++) {
      TableRow tr = new TableRow(this);
      for (int colS = 0; colS < colCount; colS++) {
        if (showedCount < dataCount) {
          Button b = new Button(this);
          TableRow.LayoutParams params =
              new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
          params.weight = 1.0f;
          b.setLayoutParams(params);
          b.setTextSize(18);
          b.setText(c.getString(1));
          final String theLegislatorId = c.getString(0);
          // 按下按鍵後進入該該委員資料頁面
          b.setOnClickListener(
              new Button.OnClickListener() {
                public void onClick(View v) {
                  Intent intent =
                      new Intent(
                          ShowCountryLegislatorActivity.this, ShowLegislatorDataActivity.class);
                  intent.putExtra("LEGIST_ID", theLegislatorId);
                  startActivity(intent);
                }
              });
          tr.addView(b);
          c.moveToNext();
          showedCount++;
        }
      }
      layout.addView(tr);
    }
    c.close();
    db.close();
  }