List of usage examples for android.widget TableLayout setOnClickListener
public void setOnClickListener(@Nullable OnClickListener l)
From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java
private void buttonSetup() { // button setup Button execute_button;/* w ww.j a v a 2 s. c o m*/ execute_button = (Button) subview.findViewById(R.id.btnRunTest); execute_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SamKnowsAggregateStatViewerActivity.this, SamKnowsTestViewerActivity.class); startActivityForResult(intent, 1); overridePendingTransition(R.anim.transition_in, R.anim.transition_out); } }); Button run_now_choice_button; run_now_choice_button = (Button) findViewById(R.id.btnRunTestChoice); run_now_choice_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { RunChoice(); } }); Button timeperiod_button; timeperiod_button = (Button) findViewById(R.id.btn_timeperiod); timeperiod_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SingleChoice(); } }); LinearLayout timeperiod_button2; timeperiod_button2 = (LinearLayout) findViewById(R.id.timeperiod_header); timeperiod_button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SingleChoice(); } }); // page turn navigation button ImageView page_right = (ImageView) findViewById(R.id.page_turn_right_agg); page_right.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { viewPager = (ViewPager) findViewById(R.id.viewPager); viewPager.setCurrentItem(1, true); } }); // grid navigation buttons Button download_grid_right_button; download_grid_right_button = (Button) subview.findViewById(R.id.btn_download_grid_right); download_grid_right_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (download_page_index < total_download_archive_records - ITEMS_PER_PAGE) { download_page_index = download_page_index + ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test1_grid); loadDownloadGrid(TestResult.DOWNLOAD_TEST_ID, R.id.agggregate_test1_grid, download_page_index, ITEMS_PER_PAGE); } }); Button download_grid_left_button; download_grid_left_button = (Button) subview.findViewById(R.id.btn_download_grid_left); download_grid_left_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (download_page_index > 0) { download_page_index = download_page_index - ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test1_grid); loadDownloadGrid(TestResult.DOWNLOAD_TEST_ID, R.id.agggregate_test1_grid, download_page_index, ITEMS_PER_PAGE); } }); Button upload_grid_right_button; upload_grid_right_button = (Button) subview.findViewById(R.id.btn_upload_grid_right); upload_grid_right_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (upload_page_index < total_upload_archive_records - ITEMS_PER_PAGE) { upload_page_index = upload_page_index + ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test2_grid); loadDownloadGrid(TestResult.UPLOAD_TEST_ID, R.id.agggregate_test2_grid, upload_page_index, ITEMS_PER_PAGE); } }); Button upload_grid_left_button; upload_grid_left_button = (Button) subview.findViewById(R.id.btn_upload_grid_left); upload_grid_left_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (upload_page_index > 0) { upload_page_index = upload_page_index - ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test2_grid); loadDownloadGrid(TestResult.UPLOAD_TEST_ID, R.id.agggregate_test2_grid, upload_page_index, ITEMS_PER_PAGE); } }); Button latency_grid_right_button; latency_grid_right_button = (Button) subview.findViewById(R.id.btn_latency_grid_right); latency_grid_right_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (latency_page_index < total_latency_archive_records - ITEMS_PER_PAGE) { latency_page_index = latency_page_index + ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test3_grid); loadDownloadGrid(TestResult.LATENCY_TEST_ID, R.id.agggregate_test3_grid, latency_page_index, ITEMS_PER_PAGE); } }); Button latency_grid_left_button; latency_grid_left_button = (Button) subview.findViewById(R.id.btn_latency_grid_left); latency_grid_left_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (latency_page_index > 0) { latency_page_index = latency_page_index - ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test3_grid); loadDownloadGrid(TestResult.LATENCY_TEST_ID, R.id.agggregate_test3_grid, latency_page_index, ITEMS_PER_PAGE); } }); Button packetloss_grid_right_button; packetloss_grid_right_button = (Button) subview.findViewById(R.id.btn_packetloss_grid_right); packetloss_grid_right_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (packetloss_page_index < total_packetloss_archive_records - ITEMS_PER_PAGE) { packetloss_page_index = packetloss_page_index + ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test4_grid); loadDownloadGrid(TestResult.PACKETLOSS_TEST_ID, R.id.agggregate_test4_grid, packetloss_page_index, ITEMS_PER_PAGE); } }); Button packetloss_grid_left_button; packetloss_grid_left_button = (Button) subview.findViewById(R.id.btn_packetloss_grid_left); packetloss_grid_left_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (packetloss_page_index > 0) { packetloss_page_index = packetloss_page_index - ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test4_grid); loadDownloadGrid(TestResult.PACKETLOSS_TEST_ID, R.id.agggregate_test4_grid, packetloss_page_index, ITEMS_PER_PAGE); } }); Button jitter_grid_right_button; jitter_grid_right_button = (Button) subview.findViewById(R.id.btn_jitter_grid_right); jitter_grid_right_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (jitter_page_index < total_jitter_archive_records - ITEMS_PER_PAGE) { jitter_page_index = jitter_page_index + ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test5_grid); loadDownloadGrid(TestResult.JITTER_TEST_ID, R.id.agggregate_test5_grid, jitter_page_index, ITEMS_PER_PAGE); } }); Button jitter_grid_left_button; jitter_grid_left_button = (Button) subview.findViewById(R.id.btn_jitter_grid_left); jitter_grid_left_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (jitter_page_index > 0) { jitter_page_index = jitter_page_index - ITEMS_PER_PAGE; } clearGrid(R.id.agggregate_test5_grid); loadDownloadGrid(TestResult.JITTER_TEST_ID, R.id.agggregate_test5_grid, jitter_page_index, ITEMS_PER_PAGE); } }); // toggle buttons TableLayout button; button = (TableLayout) findViewById(R.id.download_header); ImageView button_iv = (ImageView) findViewById(R.id.btn_download_toggle); button.setOnClickListener(this); button_iv.setOnClickListener(this); TableLayout button2; button2 = (TableLayout) subview.findViewById(R.id.upload_header); ImageView button2_iv = (ImageView) findViewById(R.id.btn_upload_toggle); button2.setOnClickListener(this); button2_iv.setOnClickListener(this); TableLayout button3; button3 = (TableLayout) subview.findViewById(R.id.latency_header); ImageView button3_iv = (ImageView) findViewById(R.id.btn_latency_toggle); button3.setOnClickListener(this); button3_iv.setOnClickListener(this); TableLayout button4; button4 = (TableLayout) subview.findViewById(R.id.packetloss_header); ImageView button4_iv = (ImageView) findViewById(R.id.btn_packetloss_toggle); button4.setOnClickListener(this); button4_iv.setOnClickListener(this); TableLayout button5; button5 = (TableLayout) subview.findViewById(R.id.jitter_header); ImageView button5_iv = (ImageView) findViewById(R.id.btn_jitter_toggle); button5.setOnClickListener(this); button5_iv.setOnClickListener(this); }
From source file:com.mifos.utils.DataTableUIBuilder.java
public LinearLayout getDataTableLayout(final DataTable dataTable, JsonArray jsonElements, LinearLayout parentLayout, final Context context, final int entityId, DataTableActionListener mListener) { dataTableActionListener = mListener; /**/* w ww .j av a2 s . co m*/ * Create a Iterator with Json Elements to Iterate over the DataTable * Response. */ Iterator<JsonElement> jsonElementIterator = jsonElements.iterator(); /* * Each Row of the Data Table is Treated as a Table Here. * Creating the First Table for First Row */ tableIndex = 0; while (jsonElementIterator.hasNext()) { TableLayout tableLayout = new TableLayout(context); tableLayout.setPadding(10, 10, 10, 10); final JsonElement jsonElement = jsonElementIterator.next(); /* * Each Entry in a Data Table is Displayed in the * form of a table where each row contains one Key-Value Pair * i.e a Column Name - Column Value from the DataTable */ int rowIndex = 0; while (rowIndex < dataTable.getColumnHeaderData().size()) { TableRow tableRow = new TableRow(context); tableRow.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); tableRow.setPadding(10, 10, 10, 10); if (rowIndex % 2 == 0) { tableRow.setBackgroundColor(Color.LTGRAY); } else { tableRow.setBackgroundColor(Color.WHITE); } TextView key = new TextView(context); key.setText(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()); key.setGravity(Gravity.LEFT); TextView value = new TextView(context); value.setGravity(Gravity.RIGHT); if (jsonElement.getAsJsonObject().get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()) .toString().contains("\"")) { value.setText(jsonElement.getAsJsonObject() .get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()).toString() .replace("\"", "")); } else { value.setText(jsonElement.getAsJsonObject() .get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()).toString()); } tableRow.addView(key, new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); tableRow.addView(value, new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.setMargins(12, 16, 12, 16); tableLayout.addView(tableRow, layoutParams); rowIndex++; } tableLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, "Update Row " + tableIndex, Toast.LENGTH_SHORT).show(); } }); tableLayout.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(context, "Deleting Row " + tableIndex, Toast.LENGTH_SHORT).show(); BaseApiManager baseApiManager = new BaseApiManager(); DataManager dataManager = new DataManager(baseApiManager); Observable<GenericResponse> call = dataManager .removeDataTableEntry(dataTable.getRegisteredTableName(), entityId, Integer.parseInt(jsonElement.getAsJsonObject() .get(dataTable.getColumnHeaderData().get(0).getColumnName()) .toString())); Subscription subscription = call.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<GenericResponse>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(GenericResponse genericResponse) { Toast.makeText(context, "Deleted Row " + tableIndex, Toast.LENGTH_SHORT).show(); dataTableActionListener.onRowDeleted(); } }); return true; } }); View v = new View(context); v.setBackgroundColor(ContextCompat.getColor(context, R.color.black)); parentLayout.addView(tableLayout); parentLayout.addView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 5)); Log.i("TABLE INDEX", "" + tableIndex); tableIndex++; } return parentLayout; }