Skip to content

Instantly share code, notes, and snippets.

@izzuddin91
Created October 9, 2018 03:22
Show Gist options
  • Save izzuddin91/a7dd9875cdf0396464f1fa7f9bafb60a to your computer and use it in GitHub Desktop.
Save izzuddin91/a7dd9875cdf0396464f1fa7f9bafb60a to your computer and use it in GitHub Desktop.
Android
mImageView = (ImageView) findViewById(R.id.imageView1);
mImageView.setImageResource(R.drawable.camera);
//for tableview function
TableLayout table = (TableLayout)findViewById(R.id.displayInputTable);
TableRow row = new TableRow(this);
row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
TableRow row2 = new TableRow(this);
row2.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
tv.setText("New Entry");
TextView tv2 = new TextView(this);
tv2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
tv2.setText("New Entry Test 2");
for (String s : title){
System.out.println(s);
TableRow row3 = new TableRow(this);
row3.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
TextView tv3 = new TextView(this);
tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
tv3.setText(s);
row3.addView(tv3);
table.addView(row3);
}
row.addView(tv);
// row.addView(tv2);
row2.addView(tv2);
table.addView(row);
table.addView(row2);
// main page
Button addBtn = (Button) findViewById(R.id.addButton);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText retrievedText = (EditText) findViewById(R.id.textfield1);
String message = retrievedText.getText().toString(); // get the text from the text field
TextView label2 = (TextView) findViewById(R.id.textView1);
label2.setText(message);
User newUser = new User(message); // test create object
System.out.println("user name is :");
System.out.println(newUser.mFirstName);
Intent secondPage = new Intent(MainActivity.this, displayInput.class); //instantiate the second page
secondPage.putExtra("name", message); //this is to get the data from the text field and pushing the data to the second page
startActivity(secondPage); // move to the second page
}
});
//second page
// paste this under class declaration , for home button action
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
// paste this on "protected void onCreate(Bundle savedInstanceState)"
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setHomeButtonEnabled(true);
Intent previousPage = getIntent();
String receivedParams = previousPage.getStringExtra("name");
Button addBtn = (Button) findViewById(R.id.backButton);
addBtn.setText(receivedParams);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
btnDisplay = (Button) findViewById(R.id.button2);
btnDisplay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int selectedId=radioGroup1.getCheckedRadioButtonId();
radioButton=(RadioButton)findViewById(selectedId);
System.out.println(radioButton.getId());
// Toast toast = Toast.makeText(getApplicationContext(),
// "This is a message displayed in a Toast",
// Toast.LENGTH_SHORT);
//
// toast.show();
Toast.makeText(MainActivity.this,radioButton.getText(),Toast.LENGTH_SHORT).show();
}
});
Switch toggle = (Switch) findViewById(R.id.switch1);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// The toggle is enabled
System.out.println("switch on");
} else {
// The toggle is disabled
System.out.println("switch off");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment