I need to display a list of options with some checked and others not, by doing a read only to avoid the modification.
But the checked boxes are no longer with the read only
table.setReadOnly();
I need to display a list of options with some checked and others not, by doing a read only to avoid the modification.
But the checked boxes are no longer with the read only
table.setReadOnly();
when I run this code it runs error.
Checkbox term3 = new Checkbox("SENG 12213 - Data Structures and Algorithms");
term3.setFont(new Font("Arial",Font.PLAIN,13));
term3.setSize(300,20);
term3.setLocation(50,310);
term3.setOpaque(false);
when I run this code, the error is 'cannot resolve the method'setOpaque(Boolen)'
how can I remove this background color?enter image description here
I've listview from the database with checkbox. My Objectives is to insert the checked listview into a table and update another table based on the checked listview. Unfortunately, my sql query did not work in the section.
Here is my full code:
package com.example.myapplication;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class DataModel extends Activity {
ConnectionClass connectionClass;
ResultSet rs;
CheckBox checkBox;
UserSessionManager session;
List<Map<String, String>> MyArrList = null;
String PFNO;
String z = "";
Boolean isSuccess = false;
String a_status = "Active";
String b_status = "Break";
TextView lblname;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkboxtest);
session = new UserSessionManager(getApplicationContext());
TextView lblName = (TextView) findViewById(R.id.lblName);
// Check user login (this is the important point)
// If User is not logged in , This will redirect user to LoginActivity
// and finish current activity from activity stack.
if(session.checkLogin())
finish();
// get user data from session
HashMap<String, String> user = session.getUserDetails();
// get name
String pfno = user.get(UserSessionManager.KEY_PF);
pfno=pfno.replaceAll("[^0-9]","");
// get email
String password = user.get(UserSessionManager.KEY_EMAIL);
// Show user data on activity
lblName.setText(Html.fromHtml(""+pfno+"" ));
// listView1
final ListView lisView1 = (ListView)findViewById(R.id.listView1);
connectionClass = new ConnectionClass();
Connection con = connectionClass.CONN();
lblname = (TextView) findViewById(R.id.lblName);
final String PIC = lblname.getText().toString();
String dates = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
String querycmd = "select Pf_no,Start_date,status from WORKTR where Scan_by ='"+PIC+"'and Start_date='"+dates+"' and status='"+a_status+"' group by Pf_no,Start_date,status ";
// where Start_date='"+dates+"' and Scan_by='"+lblname+"'
try {
Statement statement = con.createStatement();
rs = statement.executeQuery(querycmd);
MyArrList = new ArrayList<Map<String, String>>();
while (rs.next()) {
Map<String, String> map = new HashMap<String, String>();
/*** Rows 1 ***/
map = new HashMap<String, String>();
map.put("ID", rs.getString("Pf_no"));
MyArrList.add(map);
}
} catch (SQLException e) {
// Toast.makeText(.this, e.getMessage().toString(),
// Toast.LENGTH_LONG).show();
}
lisView1.setAdapter(new CountryAdapter(this));
// Check All
Button btnCheckAll = (Button) findViewById(R.id.btnCheckAll);
btnCheckAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = lisView1.getAdapter().getCount();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.ColChk);
checkbox.setChecked(true);
}
}
});
// Clear All
Button btnClearAll = (Button) findViewById(R.id.btnClearAll);
btnClearAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = lisView1.getAdapter().getCount();
for(int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.ColChk);
checkbox.setChecked(false);
}
}
});
// Get Item Checked
Button btnGetItem = (Button) findViewById(R.id.btnGetItem);
btnGetItem.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int count = lisView1.getAdapter().getCount();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.ColChk);
if(checkbox.isChecked()) {
PFNO = checkbox.getTag().toString();
Log.d("Item " + String.valueOf(i), checkbox.getTag().toString());
Toast.makeText(DataModel.this, checkbox.getTag().toString() + " Recorded for break", Toast.LENGTH_SHORT).show();
Break addPro = new Break();
addPro.execute();
// Log.d("Item "+String.valueOf(i), checkbox.getTag().toString());
//
// Toast.makeText(DataModel.this,checkbox.getTag().toString() ,Toast.LENGTH_LONG).show();
}
}
Toast.makeText(DataModel.this,"Breaktime Recorded", Toast.LENGTH_LONG).show();
}
});
}
public class Break extends AsyncTask<String, String, String> {
String z = "";
Boolean isSuccess = false;
final ListView lisView1 = (ListView)findViewById(R.id.listView1);
String PIC = lblname.getText().toString();
// String IPCpf = txt_IPC.getText().toString();
String a_status = "Active";
String b_status = "Break";
@Override
protected void onPreExecute() {
//pbbar.setVisibility(View.VISIBLE);
}
protected void onPostExecute(String r) {
//bbar.setVisibility(View.GONE);
Toast.makeText(DataModel.this, r, Toast.LENGTH_SHORT).show();
if (isSuccess) {
// Intent i = new Intent(Operation.this, Start_Page.class);
// startActivity(i);
// finish();
}
}
protected String doInBackground(String... params) {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with SQL server";
} else {
Statement st = con.createStatement();
String ReasonAll="Break-All";
String dates = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
String currentTime = DateFormat.getDateTimeInstance().format(new Date());
String query = "insert into BRTR (PF_No,start_break,work_date, reason_break) values('"+ PFNO +"','"+currentTime+"','"+dates+"', '"+ReasonAll+"' )";
st.executeQuery(query);
String query2 = ("Update WORKTR set status ='" + b_status + "' where Start_date='" + dates + "' and Pf_no='" + PFNO + "' and Scan_by='"+PIC+"' and status='"+a_status+"'");
st.executeUpdate(query2);
if( st.executeUpdate(query)==1){
Toast.makeText(DataModel.this,"Breaktime Recorded", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(DataModel.this,"Breaktime fail", Toast.LENGTH_LONG).show();
}
}
}
catch (Exception ex)
{
}
return z;
}
}
public class CountryAdapter extends BaseAdapter
{
private Context context;
public CountryAdapter(Context c)
{
//super( c, R.layout.activity_column, R.id.rowTextView, );
// TODO Auto-generated method stub
context = c;
}
public int getCount() {
// TODO Auto-generated method stub
return MyArrList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_column, null);
}
// ColID
TextView txtID = (TextView) convertView.findViewById(R.id.ColID);
txtID.setText(MyArrList.get(position).get("ID") +".");
// ColCode
// ColChk
CheckBox Chk = (CheckBox) convertView.findViewById(R.id.ColChk);
Chk.setTag(MyArrList.get(position).get("ID"));
return convertView;
}
}
}
The application result to not responding when it comes to Break operation. Please help me to view and solve this problems. If I try to put the query in the checkbox loop itself, it will only run the insert query but won't run the update query.
I have a checkbox filter in a text area for a column named "Critical Activities". I have an action control button where I need to be able to count how many boxes are checked in this filter.
I cannot seem to correctly reference this filter and count how many of the boxes are checked.
Thanks!
This is my grid which is dynamic. It is saving customer description against each checkbox. That is, if I mark the checkbox against Individual then it saves Y in my database otherwise N. so Now I just want to show tick on checkboxes that are saved Y in the database. Below is the code for my dynamic grid:
public string getCustomerStateGrid()
{
string html = ""; int Count = 1;
DataTable dt = getDataTableFromQuery(@"select Id,cuscheckbox,CustomerDescription from CustomerState3");
html = "<h2> Customer State </h2><br/><table class=\"display unbreakable\" id=\"tblCustomerDetail\" style=\"width:100%; border-collapse: collapse;\"><thead>";
#region Header
html += "<tr><th height='40' class=\"Greyheader\" style=\"width:5%\">S.No</th>";
html += "<th height='40' class=\"Greyheader\" style=\"width:30%\">Customer Status</th>";
html += "<th height='40' class=\"Greyheader\" style=\"width:15%\">Customer Description</th>";
//html += "<th class=\"Greyheader\" style=\"width:12%\">Action</th>";
html += "</tr></thead>";
#endregion
#region Body
html += "<tbody>";
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
html += "<tr class=\"GreyBorder\" id='tblCustomerDetail_" + dr["Id"].ToString() + "' pkid=\"" + dr["Id"].ToString() + "\" class=\"DataRow\">";
html += "<td class=\"GreyBorder\" style=\"text-align:center !important;\">" + Count + "</td>";
html += "<td class=\"GreyBorder\"><input id='txtcuscheckbox_" + dr["Id"].ToString() + "' type=\"checkbox\" style=\" text-align: right; width:95;\" value='" + dr["cuscheckbox"].ToString() + "' class=\"mediumTextField Customer Status\" /></td>";
html += "<td class=\"GreyBorder\"><input id='txtCustomerDescription_" + dr["Id"].ToString() + "' type=\"textbox\" style=\" text-align: right; width:95;\" value='" + dr["CustomerDescription"].ToString() + "' class=\"mediumTextField Customer Description\" /></td>";
html += "</tr>";
Count++;
}
}
else
{
html += "<tr class=\"GreyBorder\" ><td style=\"text-align:center !important;\" class=\"GreyBorder\" colspan='6'>No Data.</td></tr>";
html += "</tr>";
}
html += "</tbody>";
#endregion
html += "<tfoot><tr class='GreyBorder'>";
html += "<td class='GreyBorder' colspan='2'></td> ";
html += "</tr></tfoot>";
html += "</table><br/>";
return html.ToString();
}
I just want to customize this line of code
html += "<td class=\"GreyBorder\"><input
id='txtcuscheckbox_" + dr["Id"].ToString() + "'
type=\"checkbox\"
style=\" text-align: right; width:95;\" value='" + d
dr["cuscheckbox"].ToString() + "' class=\"mediumTextField
Customer Status\" /></td>";
so that it shows tick on checkbox. Can anyone modify my code to achieve this result? Is there any way we can do using ternary operator? 
I want to retain the checkbox values entered by the user . I want the selected values to be there when the alertdialog is opened again . I have the checkboxes in alertdialog.Once the user chooses his/her choice and then comes back ,i want the checkboxes to be checked with the previous user input till the app closes.Is there a way to do so??
I'm just doing a course exercise, where I need to make a store. When the user click in a option a table appear showing the product options where has a checkbox and a quantity selector. Well I'm trying to find a way to send more than one information through the input or validate the checkbox on the line one with the amount select also in the line one. If I send a checkbox checked on the line 1 and the amount on the line 2 it also works and messes up my database. Any suggestions? Example:
<?php
require 'connect.php';
$selection= "SELECT * from store_items";
$result = $obj_conexion->query($selection);
if($result->num_rows>0){
echo"<table border='1' align='center'>
<tr bgcolor='#E6E6E6'>
<th>Selection</th>
<th>Item Name</th>
<th>Price</th>
<th>Amount</th>
</tr>";
while ($row=$result->fetch_array()){
echo "<tr>
<td><input type='checkbox' value='".$row["product_id"]."'>
<td>".$row["product_name"]."</td>";
echo "<td>".$row["price"]."</td>";
echo "<td><input type='number' min='0' max='$row[max(amount)]' name='amount_selected'></td></tr>";
}
}else
{
echo "Error.";
}
mysqli_close($obj_conexion);
?>