I need the code to show and hide the notification bar during an activity.
I try this code:
public void goFullscreen() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.findViewById(android.R.id.content).requestLayout();
}
public void goNonFullscreen() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.findViewById(android.R.id.content).requestLayout();
}
This doesn't work after the content is adding...
Remove the following line from Android Manifest file.
android:theme="#android:style/Theme.Black.NoTitleBar" and check .
Hope it will help you.
This is the code i have used to check it .
public class Main extends Activity {
Button magic,button1,button2;
TextView display;
int random;
private Long startTime=System.currentTimeMillis();
private Handler handler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ssss);
button1=(Button)findViewById(R.id.button1);
button2=(Button)findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
goFullscreen();
}
});
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
goNonFullscreen();
}
});
}
public void goFullscreen() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.findViewById(android.R.id.content).requestLayout();
}
public void goNonFullscreen() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.findViewById(android.R.id.content).requestLayout();
}
Related
How to keep the button activity on background/pause or something like this when i press the physical back button . I want this activity to set on when i press again the button.(to show me what did i paint in last activity);
MainActivity :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonSave=(Button)findViewById(R.id.buttonDraw);
buttonSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this,ButtonDraw.class));
}
});
}
ButtonDraw :
public class ButtonDraw extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(com.example.myfirstapp.R.layout.paintingfile);
BlackPixel blackPixel;
blackPixel = new BlackPixel(this);
setContentView(blackPixel);
blackPixel.requestFocus();
}
}
In your MainActivity include this method:-
#Override
public void onBackPressed() {
startActivity(new Intent(this,ButtonDraw.class));
finish(); // this line depends on you whether you want to finish the MainActivity or not.
}
The above method gives you control over the back button of android.
how can i retrieve the checkboxes value to update the database table on pressing the update button...
TeacherLoggedInClass
public class TeacherLoggedInPage extends Activity implements OnClickListener {
Button UpdateAttendanceButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.attendancesheet);
UpdateAttendanceButton = (Button) findViewById(R.id.bUpdateAttendance);
UpdateAttendanceButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
The isChecked() method return a boolean value with the information you need.
I would also suggest you use another way with implementing the Listener. This is what Google recommends:
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click... for example your checkBox.isChecked()
}
});
}
If you want to get the single checkbox value and set database, you can follow below code,
public class TeacherLoggedInPage extends Activity implements OnClickListener {
Button UpdateAttendanceButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.attendancesheet);
UpdateAttendanceButton = (Button) findViewById(R.id.bUpdateAttendance);
UpdateAttendanceButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (cbBox.isChecked()) {
// do your operation
} else {
// do your operation
}
}
}
if you need to use a list of checkbox status to update databases, you'd better to create a collection to cache every checkbox status , and with bulkInsert or transaction to commit.
What is the force close problem of this program?
public class MyActivity extends Activity {
TextView t=(TextView)findViewById(R.id.textView1);
Button r=(Button)findViewById(R.id.button2);
private OnClickListener i=new OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
t.setText("fghffghfhgf");
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
r.setOnClickListener(i);
}
}
You need to get your TextView and Button after inflating the layout.
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//here inflate the layout
setContentView(R.layout.main);
//now you can get your widgets
final TextView t= (TextView)findViewById(R.id.textView1);
Button r=(Button)findViewById(R.id.button2);
r.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
t.setText("fghffghfhgf");
}
};
);
}
}
I really recommend you to check this to build your first app.
I need to toast the stopwatch's value
ie.,time taken between start and stop
If i click the stop button it should toast that time duration.
How to do this?
Here i have tried some code
chrono_meter.java
public class Chrono_meter extends Activity {
Chronometer chr;
Button btn_stop_travel;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chronometer_layout);
chr = (Chronometer)findViewById(R.id.chronometer1);
chr.start();
btn_stop_travel = (Button)findViewById(R.id.btn_stop_inspection);
btn_stop_travel.setOnClickListener(mStopListener);
}
View.OnClickListener mStopListener = new OnClickListener() {
public void onClick(View v) {
chr.stop();
}
};
}
Try this
View.OnClickListener mStopListener = new OnClickListener() {
public void onClick(View v) {
chr.stop();
Toast.makeText(Chrono_meter.this, chr.getText(), Toast.LENGTH_LONG).show() ;
}
};
i writed an application which contains an option button and Option Activity.
In the OptionActivity, you can choose play a music "on" or "off" with togglebutton. and there are some check button also.
until here everything is okey but when you check some box and back to the main menu and back to the Options Activity again, you find that all variables is default value. for example the checked box one is uncheckhed. I know that it is because of everyCall the Options Activity with new Intent but i want to know that starting an activity "without using new Intent"
This is my SPLASH SCREEN
public class MainActivity extends Activity {
/* (non-Javadoc)
* #see android.app.Activity#onCreate(android.os.Bundle)
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.baslangic);
Thread thred=new Thread(){
public void run(){
try {
sleep(5000);
startActivity(new Intent("com.KAYA.ingilizce_gelistirme.OPTIONS"));
startActivity(new Intent("com.KAYA.ingilizce_gelistirme.BASLANGIC"));
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
finish();
}
}
};
thred.start();
}
}
This is my MAIN ACTÄ°VTY which contains options button
public class Baslangic extends Activity {
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button start=(Button)findViewById(R.id.button1);
Button options=(Button)findViewById(R.id.button2);
Button about=(Button)findViewById(R.id.button3);
start.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent("com.KAYA.ingilizce_gelistirme.OYUN"));
}
});
options.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
about.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent("com.KAYA.ingilizce_gelistirme.ABOUT"));
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
And This is My options Activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.options);
it=(RadioButton)findViewById(R.id.radio0);
ti=(RadioButton)findViewById(R.id.radio1);
final ToggleButton but=(ToggleButton)findViewById(R.id.toggleButton1);
music=MediaPlayer.create(Options.this, R.raw.avril);
but.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(but.isChecked())
music.start();
else
music.pause();
}
});
it.setChecked(true);
Button menu=(Button)findViewById(R.id.button1);
menu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent("com.KAYA.ingilizce_gelistirme.BASLANGIC"));
}
});
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
startActivity(new Intent("com.KAYA.ingilizce_gelistirme.BASLANGIC"));
}
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
#Override
protected void onStop() {
super.onStop();
}
}
NOTE: Be aware That when the user click the options Button, i call finish(), actually i have a solution. My solution that, after the splash screen, i start 2 activity; first Options later Menu, And when the user click the Options button and i call the finish() so i am in the options Button :D and when press back i called new Intent(menu) you can see on OPTIONS activity,
So my problem is already solved but i want to know that there should be a solution different from this way, If you know pls help me. :)
Are you using the PreferenceActivity or a normal Activity superclass?
Anyway, be sure to read about the SharedPreferences - it can store your values for entire app or for single activity.