Hi i want disable the status bar in an java app android, like when the user pull down the bar doesnt go down
Hello bro use This one!
Use this code for hiding the status bar in your app and easy to use
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
If what u want is full screen activity, use this
public class sample extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreen();
//add your code
}
private void setFullScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
getWindow().getInsetsController().hide(WindowInsets.Type.statusBars() | WindowInsets.Type.statusBars());
getWindow().getInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}else {
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN,LayoutParams.FLAG_FULLSCREEN);
}
}
}
If you're saying that u don't status bar to open, then that isn't possible.
You can't show and hide native status bar of android, the system doesn't allow you to do that. But you can create your own customized status, then you can show it and hide it as you want.
Here and example:
custom_status.xml
<com.google.android.material.card.MaterialCardView
android:id="#+id/mToolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="#color/white"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="15dp"
android:layout_marginVertical="15dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="2dp"
android:textColor="#color/black"
android:textSize="32sp"
app:layout_constraintBottom_toBottomOf="#+id/backButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/backButton"
app:layout_constraintTop_toTopOf="#+id/backButton" />
<ImageView
android:id="#+id/backButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:background="#drawable/ic_circle_solid"
android:backgroundTint="#color/quantum_grey100"
android:padding="7dp"
android:src="#drawable/ic_baseline_arrow_back_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
in java code
public void onScrollStateChanged(AbsListView view, int scrollState) {
final ListView lw = getListView();
if (view.getId() == lw.getId()) {
final int currentFirstVisibleItem = lw.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
mIsScrollingUp = false;
//mToolbar_container visible
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
mIsScrollingUp = true;
//mToolbar_container gone
}
}
}
Related
if (type=="dialer") {
String timestamp = list.get(position).get(Constants.DATE);
holder.txtTimestamp.setVisibility(View.VISIBLE);
holder.imgDelete.setVisibility(View.GONE);
holder.txtTimestamp.setText(getDate(Long.parseLong(timestamp),"dd/MM/yyyy hh:mm:ss"));
if (Integer.parseInt(callType) == CallLog.Calls.BLOCKED_TYPE)
holder.imgCallType.setImageDrawable(context.getResources().getDrawable(R.drawable.block));
if (Integer.parseInt(callType) == CallLog.Calls.BLOCKED_TYPE)
holder.imgCallType.setImageDrawable(context.getResources().getDrawable(R.drawable.rejected));
if (Integer.parseInt(callType) == CallLog.Calls.OUTGOING_TYPE)
holder.imgCallType.setImageDrawable(context.getResources().getDrawable(R.drawable.outgoing_call));
if (Integer.parseInt(callType) == CallLog.Calls.INCOMING_TYPE)
holder.imgCallType.setImageDrawable(context.getResources().getDrawable(R.drawable.incoming_call));
if (Integer.parseInt(callType) == CallLog.Calls.MISSED_TYPE)
holder.imgCallType.setImageDrawable(context.getResources().getDrawable(R.drawable.missed_call));
if (Integer.parseInt(callType) == CallLog.Calls.ANSWERED_EXTERNALLY_TYPE)
holder.imgCallType.setImageDrawable(context.getResources().getDrawable(R.drawable.call_received));
}else if (type=="contact") {
holder.txtTimestamp.setVisibility(View.GONE);
holder.imgCallType.setVisibility(View.GONE);
holder.imgDelete.setVisibility(View.GONE);
}else if (type=="favourite"){
holder.txtTimestamp.setVisibility(View.GONE);
holder.imgCallType.setVisibility(View.GONE);
}
// listener
Bitmap finalBitmap = imgBitmap;
holder.imgPic.setOnLongClickListener(view -> {
CustomDialog imageDialog = new CustomDialog(activity,R.layout.image_dialog,"","","", finalBitmap);
imageDialog.setCancelable(true);
imageDialog.show();
return false;
});
holder.itemView.setOnLongClickListener(view->{
if (type=="dialer"){
}else if (type=="contact"){
Intent intent = new Intent(context, ContactDetailsActivity.class);
intent.putExtra("id",list.get(position).get(Constants.ID));
context.startActivity(intent);
}else if (type=="favourite"){
Intent intent = new Intent(context, FavouriteContactDetailsActivity.class);
intent.putExtra(Constants.FAVOURITE_ID,list.get(position).get(Constants.FAVOURITE_ID));
intent.putExtra(Constants.ID,list.get(position).get(Constants.ID));
ActivityOptions anim = ActivityOptions.makeSceneTransitionAnimation(activity);
context.startActivity(intent, anim.toBundle());
}
return false;
});
holder.imgDelete.setOnClickListener(v->{
SqliteFavourite sqliteFavourite = new SqliteFavourite(context.getApplicationContext());
boolean check = sqliteFavourite.deleteData("",list.get(position).get(Constants.ID));
if (check)
Snackbar.make(v,"Successfully deleted",Snackbar.LENGTH_SHORT).show();
else Snackbar.make(v,"Error occurred when deleting",Snackbar.LENGTH_SHORT).show();
});
holder.itemView.setOnClickListener(view->{
call(activity,phoneNumber);
});
I was using these code in an adapter.
#Override
public int getItemCount() {
return list.size();
}
#Override
public int getItemViewType(int position) {
return position;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView txtContactName,txtContactNumber,txtTimestamp;
ImageView imgPic,imgCallType,imgDelete;
ConstraintLayout contactItem;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
txtContactName = itemView.findViewById(R.id.txtName);
txtContactNumber = itemView.findViewById(R.id.txtContactNumber);
txtTimestamp = itemView.findViewById(R.id.txtTimestamp);
imgPic = itemView.findViewById(R.id.imgContact);
imgCallType = itemView.findViewById(R.id.imgCallType);
contactItem = itemView.findViewById(R.id.contactItem);
imgDelete = itemView.findViewById(R.id.imgDeleteContact);
}
}
Whenever I am clicking on first or second item then I can hear the clickListener. But when I click on 3rd 4th or higher item then I can't hear the clickListener. Even I had set a selector there but the selector is only working for 1st and 2nd
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/contactItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:clickable="true">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgContact"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/user_profile"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<TextView
android:id="#+id/txtName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Name"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/txtContactNumber"
app:layout_constraintEnd_toStartOf="#+id/imgCallType"
app:layout_constraintStart_toEndOf="#+id/imgContact"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/txtContactNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Contact Number"
app:layout_constraintBottom_toTopOf="#id/txtTimestamp"
app:layout_constraintEnd_toStartOf="#+id/imgCallType"
app:layout_constraintStart_toEndOf="#+id/imgContact"
app:layout_constraintTop_toBottomOf="#+id/txtName" />
<TextView
android:id="#+id/txtTimestamp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="TextView"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/txtContactNumber"
app:layout_constraintStart_toEndOf="#+id/imgContact"
app:layout_constraintTop_toBottomOf="#id/txtContactNumber" />
<ImageView
android:id="#+id/imgCallType"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/call_received"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imgDeleteContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#android:drawable/ic_menu_delete" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
When I scroll down then I can hear the listener but whenever I am on top at that layout then I can't access the listener in 3rd or more. Why it's happening? I am not getting any error in logcat. Although I can't click on some items why? I had tried to use holder.contactItem.setOn.... but it wasn't working also.
When I scroll down I can listen the click. But whenever I am at top I can't listen. But I wonder I can click on Image. I meant holder.imgPic.setOnLongClickListener......
I have set onTouchListener to itemView but it's working. It's only not working for onCLickListener and onLongClickListener (As I said earlier it's working when I scroll down).
I have tried
android:focusable="false"
android:clickable="false"
android:longClickable="false"
although I was facing the same issue. I had used them in Constraint Layout which I declared as contactItem. Then I had tried holder.contactItem instead of holder.itemView
I'm trying to create a form to capture data, I need to access the camera to take pictures. My problem is when I try to call the camera with imagenButton, it's not working but the code doesn't show any error.
Here's my fragment to declare form:
public class EspecimenesInsertarFragment extends Fragment implements
Response.Listener<JSONObject>, Response.ErrorListener {
private EspecimenesViewModel especimenesViewModel;
RequestQueue rq;
JsonRequest jrq;
final int COD_SELECCIONA=10;
final int COD_FOTO=20;
private static final int REQUEST_IMAGE_CAMERA=101;
private static final int REQUEST_PERMISSION_CAMERA=101;
Button btnGuardar, btnCancelar;
ImageButton btnCamara, btnGaleria;
ImageView imageView;
public static final int MY_DEFAULT_TIMEOUT = 50000;
public EspecimenesInsertarFragment() {
// Required empty public constructor
}
public static EspecimenesInsertarFragment newInstance() { return new EspecimenesInsertarFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view;
view = inflater.inflate(R.layout.fragment_colecciones_insertar, container, false);
imageView = (ImageView)view.findViewById(R.id.imageView);
btnCamara=(ImageButton) view.findViewById(R.id.tomarFoto);
btnGuardar = (Button) view.findViewById(R.id.buttonIngresarEspecimenes);
rq = Volley.newRequestQueue(getContext());
/* if(validaPermisos()){
btnCamara.setEnabled(true);
}else{
btnCamara.setEnabled(false);
} */
if (ContextCompat.checkSelfPermission(getContext(), WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(), new String[]{WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA}, 1000);
}
btnGuardar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
registrar_especimen("http://localhost/BIO-UES-APP/EspecimenesController.php");
}
});
static final int REQUEST_TAKE_PHOTO=1;
public void tomarFoto(View view){
Intent takePictureInent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Log.d("entra","");
if(takePictureInent.resolveActivity(getActivity().getPackageManager())!= null){
File photoFile=null;
try {
photoFile=createImageFile();
}catch (IOException ex){
}
if(photoFile!=null){
Uri photoUri=FileProvider.getUriForFile(getActivity(),"com.example.luvin.drawercero",photoFile);
takePictureInent.putExtra(MediaStore.EXTRA_OUTPUT,photoUri);
getActivity().startActivityForResult(takePictureInent,REQUEST_TAKE_PHOTO);
}
}
}
And this is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Especimenes.EspecimenesConsultarFragment">
<!-- TODO: Update blank fragment layout -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="-7dp"
android:layout_marginRight="-7dp"
android:layout_marginBottom="9dp"
tools:layout_editor_absoluteX="393dp"
tools:layout_editor_absoluteY="79dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageButton
android:id="#+id/tomarFoto"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="100dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:clickable="true"
android:src="#android:drawable/ic_menu_camera" />
<ImageButton
android:id="#+id/seleccionarDesdeGaleria"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="200dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:src="#android:drawable/ic_menu_gallery" />
</FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="88dp"
android:orientation="vertical">
<Button
android:id="#+id/buttonCancelarEspecimenes"
android:layout_width="129dp"
android:layout_height="41dp"
android:layout_toRightOf="#+id/buttonIngresar"
android:backgroundTint="#96A6A8"
android:gravity="center|left"
android:text="CANCELAR"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.783"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.659" />
<Button
android:id="#+id/buttonIngresarEspecimenes"
android:layout_width="129dp"
android:layout_height="41dp"
android:layout_marginStart="68dp"
android:text="INGRESAR"
app:backgroundTint="#00BCD4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/buttonCancelar"
app:layout_constraintHorizontal_bias="0.85"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.659" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
Logcat message when button is pressed:
com.example.luvin.drawercero D/ViewRootImpl#6731d38[MainActivity]: ViewPostIme pointer 1
To complete my question, I have the permissions in the manifest. I already tried to call the camera in another way, tried creating the method in the MainActivity to create the OnClick event in the XML Layout, but nothing works.
If anyone knows how to solve this issue please help.
Thanks.
You forgot to add the on click listener to your photo button. This should solve your problem:
btnCamara = view.findViewById(R.id.tomarFoto);
btnCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tomarFoto(v);
}
});
I am building this application on android studio and i am trying to link my button with next activity which is login screen. before i had it working with register screen but then i messed up with code now it just doesn't work when i run the application and click on register button my app crashes and shuts down and login button doesn't even do anything.
below is the code for main page activity and login page activity
first i will paste frontpage activity code where the button is, then its java class, then i will paste loginpage activity and then its java class.
can someone pls advice me how to call the login activity from the login button on the front page.
thank you so much in advance
frontpage activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Login">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#drawable/bg3"
android:gravity="center|top">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Easy Booking"
android:id="#+id/textView"
android:textSize="33dp"
android:gravity="center"
android:textColor="#0c0c0c"
/>
<Button
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:id="#+id/btLogin"
android:onClick="bLogin"
android:background="#null"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="108dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Register"
android:id="#+id/btRegister"
android:onClick="bRegister"
android:background="#null"
android:layout_gravity="center_horizontal" />
</LinearLayout>
now its java class
public class Frontpage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frontpage);
//OnclickButtonListener();
}
public void bLogin(View view) {
}
public void onButtonClick(View v){
if (v.getId() == R.id.btRegister) {
Intent i = new Intent(new Intent(Frontpage.this, Register.class));
startActivity(i);
}
}
/**
public void OnclickButtonListener(){
button = (Button)findViewById(R.id.bRegister);
button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("/Users/umairfarooq/AndroidStudioProjects/Easybooking/app/src/main/res/layo ut/activity_register");
startActivity(intent);
}
}
);
} /**#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity_login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
*/}
below is the login activity
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#635b5b"
android:orientation="vertical"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Form"
android:textAppearance="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Email"
android:id="#+id/etUsername"
android:layout_gravity="center_horizontal"
android:layout_marginTop="70dp"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Password"
android:id="#+id/etPassword"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:inputType="textPassword"
/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:onClick="userLogin"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Now"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="userReg"
/>
</LinearLayout>
and now login java class
package com.example.umairfarooq.easybooking;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
public class Login extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void buttonOnClick (View v){
}
}
The problem is that your activities don't contain the methods that you've set for your buttons' android:onClick attribute.
For the layout that the Frontpage activity is using, you can either change btRegister button's android:onClick attribute to android:onClick="onButtonClick" or create a public void bRegister(View v){...} method in that activity.
For the Login activity, the layout has two buttons with their android:onClick attribute set to userReg and userLogin, you can either create those methods in the activity or change both of those attributes values to buttonOnClick.
when i run the application and click on register button my app crashes
and shuts down
It is because this button:
<Button
android:layout_width="108dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Register"
android:id="#+id/btRegister"
android:onClick="bRegister"
android:background="#null"
android:layout_gravity="center_horizontal" />
in your frontpage activity needs a method with signature public void bRegister(View view) in your FrontPage.java class. As you do not have this method, it crashes.
login button doesn't even do anything
The reason is, this button
<Button
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:id="#+id/btLogin"
android:onClick="bLogin"
android:background="#null"
android:layout_gravity="center_horizontal" />
in your frontpage activity needs a method called public void bLogin(View view) in your Frontpage.java class. Though the method is present, you do not have any code in it, hence it does not do anything.
You need to add proper code in bLogin method so that your login button starts functioning, and even before that add a bRegister method so that your register button starts working.
Hope this helps you.
I am trying to make a popup window in an activity. The popup window shows up when we click a button in the activity. The layout for popup window is to show a radio group containing 4 radio buttons, a button and a seek bar and has to return a value to the main activity based on the selected radio button when the button in the pop up window is pressed.
When i run the app and open the pop up window it is giving we this error:
"java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)' on a null object reference "
The code for my main activity is:
public class CustomMenuActivity extends Activity
{
String ingredientName;
String ingredientQuantity;
private PopupWindow pw;
Button setQuantity;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_menu);
setQuantity = (Button) findViewById(R.id.btnSetQty);
setQuantity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
initiatePopupWindow();
}
});
}
private void initiatePopupWindow()
{
try {
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater) CustomMenuActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.set_quantity_popup,
(ViewGroup) findViewById(R.id.popupElementid));
// create a 600px width and 570px height PopupWindow
pw = new PopupWindow(layout, 600, 570, true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
RadioGroup radioGroup;
radioGroup = (RadioGroup) findViewById(R.id.radioGroupid);
final String[] tempQtyVar = new String[1];
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.rbqty30id:
tempQtyVar[0] = "30";
break;
case R.id.rbqty60id:
tempQtyVar[0] = "60";
break;
case R.id.rbqty90id:
tempQtyVar[0] = "90";
break;
case R.id.rbqtycutomid:
tempQtyVar[0] = "120";
break;
}
}
});
Button setQtyBtn = (Button) layout.findViewById(R.id.buttonOkSetQtyid);
setQtyBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ingredientQuantity = tempQtyVar[0];
Toast.makeText(getApplicationContext(),ingredientQuantity,Toast.LENGTH_LONG).show();
pw.dismiss();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
The layout.xml for my pop up window is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#fd050505"
android:padding="30dp"
android:id="#+id/popupElementid">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="#+id/relativeLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SET QUANTITY"
android:textColor="#84e9e6"
android:textSize="20sp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:id="#+id/popupTitleid"/>
<LinearLayout
android:layout_width="600dp"
android:layout_height="wrap_content"
android:layout_below="#+id/popupTitleid"
android:orientation="horizontal"
android:background="#drawable/btn_rounded_boarder"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/radioGroupid"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 30ml "
android:textColor="#84e9e6"
android:id="#+id/rbqty30id"
android:checked="true" />
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#84e9e6"
android:text=" 60ml "
android:id="#+id/rbqty60id" />
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#84e9e6"
android:text=" 90ml "
android:id="#+id/rbqty90id" />
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#84e9e6"
android:text=" Custom Value "
android:id="#+id/rbqtycutomid"
/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="600dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true">
<SeekBar
android:id="#+id/customqtySBid"
android:layout_height="fill_parent"
android:layout_width="600dp"
android:textColor="#84e9e6"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="150dp"
android:paddingBottom="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonOkSetQtyid"
android:textColor="#84e9e6"
android:text="OK"
android:background="#drawable/btn_rounded_boarder"
android:layout_marginTop="275dp"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
I tried looking for answer online but didn't really find solution specific to my problem. Please suggest any solutions.
Thanks in advance.
You seem to be inflating the wrong layout. Change the correct layout.xml in
setContentView(R.layout.activity_custom_menu);
When I am passing image url to Picasso then it shows me error "Target must not be null". When I fetch image from url using Picasso then it shows me error. Even my id assigned to image is correct. At last I replaced the image url with static image, though I receive error as same.
Here is my code:
public class MainScreen extends AppCompatActivity {
private ImageView user_profile_pic,img2;
private ImageView like_button,dislike_button,location_button,refresh;
private ArrayList<String> al;
private ArrayAdapter<String> arrayAdapter;
private int i;
private SwipeFlingAdapterView flingContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
//Setting
user_profile_pic=(ImageView)findViewById(R.id.profile_image);
img2=(ImageView)findViewById(R.id.img2);
//Picasso.with(getApplicationContext()).load("https://pbs.twimg.com/profile_images/596282530652753921/bPf8NmOs.jpg").into(user_profile_pic);
//Picasso.with(getApplicationContext()).load(android.R.drawable.btn_star).into(img);
Picasso.with(getApplicationContext()).load("https://pbs.twimg.com/profile_images/596282530652753921/bPf8NmOs.jpg")
.placeholder(android.R.drawable.btn_star)
.error(android.R.drawable.btn_star)
.into(img2);
flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
al = new ArrayList<>();
al.add("php");
al.add("c");
al.add("python");
al.add("java");
al.add("html");
al.add("c++");
al.add("css");
al.add("javascript");
arrayAdapter = new ArrayAdapter<>(this, R.layout.custom_user_details, R.id.helloText, al );
flingContainer.setAdapter(arrayAdapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
#Override
public void removeFirstObjectInAdapter() {
Log.d("LIST", "removed object!");
al.remove(0);
arrayAdapter.notifyDataSetChanged();
}
#Override
public void onLeftCardExit(Object dataObject) {
Toast.makeText(getApplicationContext(),"Left !",Toast.LENGTH_SHORT).show();
}
#Override
public void onRightCardExit(Object dataObject) {
Toast.makeText(getApplicationContext(),"Right !",Toast.LENGTH_SHORT).show();
}
#Override
public void onAdapterAboutToEmpty(int itemsInAdapter) {
al.add("XML ".concat(String.valueOf(i)));
arrayAdapter.notifyDataSetChanged();
Log.d("LIST", "notified");
i++;
}
#Override
public void onScroll(float scrollProgressPercent) {
try
{
View view = flingContainer.getSelectedView();
view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercent < 0 ? -scrollProgressPercent : 0);
view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0);
}
catch (NullPointerException e) {
Log.e("tag", "NullPointerException" + e);
}
}
});
//flingContainer.getTopCardListener().selectRight(); To remove view from right side while pressing button
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_screen, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And this is what my xml is:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="80">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/img2"
android:src="#android:drawable/btn_star"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:padding="8dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vimal, "
android:id="#+id/helloText"
android:textColor="#android:color/black"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23"
android:textColor="#android:color/black"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#android:drawable/btn_dialog"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="25sp"
android:layout_marginLeft="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#android:drawable/btn_dialog"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="25sp"
android:layout_marginLeft="5dp"
android:layout_gravity="center"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/item_swipe_left_indicator"
android:alpha="0"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:background="#A5F" />
<View
android:id="#+id/item_swipe_right_indicator"
android:alpha="0"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_gravity="right"
android:background="#5AF" />
</FrameLayout>
img2 is null, and you're passing that into the into function.
Add a null check after img2=(ImageView)findViewById(R.id.img2); to check when it stops being null or whether it stays null while you're testing, or just to confirm that it is null.
Check your layout ID's and make sure they're right for ALL the configurations, and make sure you have #+id/img2 specified .
are you sure load the correct layout ? because you have R.id.profile_image in Java file, but i didn't found that id in your xml file.
You can't download image from https using Picasso library.
you can use this library.
try to change it as..
Picasso.with(MainScreen.this).load("https://pbs.twimg.com/profile_images/596282530652753921/bPf8NmOs.jpg")
.placeholder(android.R.drawable.btn_star)
.error(android.R.drawable.btn_star)
.into(img2);
also make sure that you are using the activity_main_screen.xml layout and check the id if img2 there.