logo
down
shadow

android app behaving strangely


android app behaving strangely

By : tapchi18
Date : November 14 2020, 04:48 PM
help you fix your problem I am creating a simple app which will take data from the user to signup and then allow users to login. , This is the final solution:
activity_login.xml
code :
<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" 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=".Login">

    <TextView android:text="Login to Control Panel" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/login_text"
        android:textSize="20dp"
        android:layout_alignRight="@+id/login_username"
        android:layout_alignEnd="@+id/login_username"
        android:layout_alignLeft="@+id/login_username"
        android:layout_alignStart="@+id/login_username" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"
        android:id="@+id/login_button"
        android:layout_alignParentBottom="true"/>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Signup"
        android:id="@+id/signup_button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/login_username"
        android:hint="Username"
        android:layout_above="@+id/login_password"
        android:layout_alignLeft="@+id/login_password"
        android:layout_alignStart="@+id/login_password"
        android:layout_toLeftOf="@+id/signup_button"
        android:layout_toStartOf="@+id/signup_button" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/login_password"
        android:hint="Password"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
public class Login extends ActionBarActivity {

    EditText login_username, login_password;
    String uname, pass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        login_username = (EditText) findViewById(R.id.login_username);
        login_password = (EditText) findViewById(R.id.login_password);

        final Button switchsignup = (Button) findViewById(R.id.signup_button);
        switchsignup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent act2 = new Intent(view.getContext(), Signup.class);
                startActivity(act2);
            }
        });

        /*
            - TIP -

            Try always to do as the following instead of call a method into the xml; because you have
            more control of which xml is being called right here
        */
        final Button btLogin = (Button) findViewById(R.id.login_button);
        btLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent act2 = new Intent(view.getContext(), Signup.class);
                startActivity(act2);
            }
        });   


    }

    //Method to get list value pair and form the query
    private String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException {
        StringBuilder result = new StringBuilder();
        boolean first = true;

        for (NameValuePair pair : params) {
            if (first)
                first = false;
            else
                result.append("&");

            result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
            result.append("=");
            result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
        }

        return result.toString();
    }

    //Method to post data to webservice
    public void post() throws UnsupportedEncodingException
    {
        try
        {
            // Calling async task to get json
            new DownloadOperation().execute();

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    //Handle popout messages
    public void error(boolean flag, String etext) {
        if (flag == true) {
            Toast.makeText(getBaseContext(), etext, Toast.LENGTH_SHORT).show();
            //Code to handle failure
            login_username.setText("");
            login_password.setText("");

        } else {
            Toast.makeText(getBaseContext(), etext, Toast.LENGTH_SHORT).show();
            setContentView(R.layout.activity_welcome);

        }
    }

    //Asynctask
    private class DownloadOperation extends AsyncTask<Void, Void, String> {
        String uname = "";
        String pass = "";
        ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Get user defined values
            uname = login_username.getText().toString();
            pass = login_password.getText().toString();

            //Initiate ProgressBar
            dialog = ProgressDialog.show(Login.this, "Please Wait", "Loggin you in ...");
        }

        @Override
        protected String doInBackground(Void... params) {
            String response = "";
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://rgbpallete.in/led/api/login");
            HttpEntity httpEntity = null;
            HttpResponse httpResponse = null;
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("uname", uname));
                nameValuePairs.add(new BasicNameValuePair("pass", pass));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                httpResponse = httpclient.execute(httppost);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                httpEntity = httpResponse.getEntity();
                response = EntityUtils.toString(httpEntity);
                return response;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String jsonStr) {
            super.onPostExecute(jsonStr);
            dialog.dismiss();
            Log.d("tag", "Result:\n" + jsonStr);
            if (jsonStr != null) {
                try{
                    JSONObject jsonObj = new JSONObject(jsonStr);
                    String message = jsonObj.getString("message");
                    boolean error = jsonObj.getBoolean("error");

                    error(error,message);

                }
                catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");
            }
        }
    }



    @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_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);
    }

}
<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" 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="in.techbreeze.android.cake.Signup">

    <TextView android:text="Enter details to signup" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/signup_text" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Back"
        android:id="@+id/back_button"
        android:layout_marginBottom="71dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="71dp"
        android:layout_marginEnd="71dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/signup_username"
        android:layout_marginTop="92dp"
        android:hint="Username"
        android:layout_below="@+id/signup_text"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/signup_password"
        android:layout_alignEnd="@+id/signup_password" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/signup_password"
        android:layout_below="@+id/signup_username"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:hint="Password" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/signup_cpassword"
        android:layout_below="@+id/signup_password"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:hint="Confirm Password" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/signup_email"
        android:layout_below="@+id/signup_cpassword"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:hint="Email" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:ems="10"
        android:id="@+id/signup_phone"
        android:layout_below="@+id/signup_email"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:hint="Phone Number" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Singup"
        android:id="@+id/signup_button"
        android:layout_above="@+id/back_button"
        android:layout_alignRight="@+id/back_button"
        android:layout_alignEnd="@+id/back_button"/>

</RelativeLayout>
public class Signup extends ActionBarActivity {

EditText signup_username, signup_password, signup_cpassword, signup_email, signup_phone;
String pass, cpass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    signup_username = (EditText) findViewById(R.id.signup_username);
    signup_password = (EditText) findViewById(R.id.signup_password);
    signup_cpassword = (EditText) findViewById(R.id.signup_cpassword);
    signup_email = (EditText) findViewById(R.id.signup_email);
    signup_phone = (EditText) findViewById(R.id.signup_phone);

    /*
        - TIP -

        finish(); instead of Intent act2 = new Intent(view.getContext(), Login.class);
            startActivity(act2);

        When you call startActivity you call another activity and don't back to the last activity. For this, you
        have to use finish() instead.

    */
    final Button switchlogin = (Button) findViewById(R.id.back_button);
    switchlogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });

    /*
        - TIP -

        It's like the Login.java TIP

        Try always to do as the following instead of call a method into the xml; because you have
        more control of which xml is being called right here
    */
    final Button btSignup = (Button) findViewById(R.id.signup_button);
    btSignup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try{

                pass = signup_password.getText().toString();
                cpass = signup_cpassword.getText().toString();

                if(pass.equals(cpass))
                {
                    // CALL post method to make post method call
                    post();
                }
                else
                {
                    Toast.makeText(getBaseContext(), "Passwords mismatch", Toast.LENGTH_SHORT).show();
                    signup_password.setText("");
                    signup_cpassword.setText("");

                }
            }
            catch(Exception ex)
            {
                String error = ex.getMessage();
            }
        }
    });
}

//Method to get list value pair and form the query
private String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException {
    StringBuilder result = new StringBuilder();
    boolean first = true;

    for (NameValuePair pair : params) {
        if (first)
            first = false;
        else
            result.append("&");

        result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
        result.append("=");
        result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
    }

    return result.toString();
}

//Method to post data to webservice
public void post() throws UnsupportedEncodingException
{
    try
    {
        // Calling async task to get json
        new DownloadOperation().execute();

    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

//Handle popout messages
public void error(boolean flag, String etext) {
    if (flag == true) {
        Toast.makeText(getBaseContext(), etext, Toast.LENGTH_SHORT).show();
        //Code to handle failure
        signup_username.setText("");
        signup_password.setText("");
        signup_cpassword.setText("");
        signup_email.setText("");
        signup_phone.setText("");

    } else {
        Toast.makeText(getBaseContext(), etext, Toast.LENGTH_SHORT).show();

        /*
            - TIP -

            finish() instead of setContentView(R.layout.activity_login)

            You have to finalize the activity instead of set another content or call startActivity to back.

            You cannot do like you did here(setContentView(R.layout.activity_login)); because doing it you just change the xml and
            not change the activity, so causing the error that you posted
        */
        finish();

    }
}

//Asynctask
private class DownloadOperation extends AsyncTask<Void, Void, String> {
    String uname, pass, cpass, email, phone;
    ProgressDialog dialog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Get user defined values
        uname = signup_username.getText().toString();
        pass = signup_password.getText().toString();
        cpass = signup_cpassword.getText().toString();
        email = signup_email.getText().toString();
        phone=signup_phone.getText().toString();


        //Initiate ProgressBar
        dialog = ProgressDialog.show(Signup.this, "Please Wait", "Signing you up ...");
    }

    @Override
    protected String doInBackground(Void... params) {
        String response = "";
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://rgbpallete.in/led/api/signup");
        HttpEntity httpEntity = null;
        HttpResponse httpResponse = null;
        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
            nameValuePairs.add(new BasicNameValuePair("uname", uname));
            nameValuePairs.add(new BasicNameValuePair("pass", pass));
            nameValuePairs.add(new BasicNameValuePair("email", email));
            nameValuePairs.add(new BasicNameValuePair("phone", phone));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httpResponse = httpclient.execute(httppost);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            httpEntity = httpResponse.getEntity();
            response = EntityUtils.toString(httpEntity);
            return response;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String jsonStr) {
        super.onPostExecute(jsonStr);
        dialog.dismiss();
        Log.d("tag", "Result:\n" + jsonStr);
        if (jsonStr != null) {
            try{
                JSONObject jsonObj = new JSONObject(jsonStr);
                String message = jsonObj.getString("message");
                boolean error = jsonObj.getBoolean("error");

                error(error,message);

            }
            catch (JSONException e) {
                e.printStackTrace();
            }
        }
        else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }
    }
}


@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_signup, 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);
}


Share : facebook icon twitter icon
Android Image Button Behaving Strangely

Android Image Button Behaving Strangely


By : user3636614
Date : March 29 2020, 07:55 AM
Hope this helps Solved! stupid, stupid me...
Next button was displaying as selected because in my code (part not posted) disables the button during my fadePageOut() method (see posted code). The state-drawable was simply using the wrong images for enabled/disabled states.
code :
<item android:state_enabled="false" android:drawable="@drawable/prev_arrowhigh"/>
<item android:state_enabled="false" android:drawable="@drawable/prev_arrow"/>
Android Preference value behaving strangely

Android Preference value behaving strangely


By : user2348420
Date : March 29 2020, 07:55 AM
This might help you Solved it!
I had a poke through the source code for EditTextPreference and realized it initialized its internal storage variable as soon as it was initialized and not (as I had for some reason assumed) when the preference was actually tapped.
DetailTextLabel behaving strangely

DetailTextLabel behaving strangely


By : หิน เหล็ก ไฟ
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The solution turned out to be that the strings contained allot of initial whitespace, resulting in them being padded out of the view.
Android actionbar behaving strangely

Android actionbar behaving strangely


By : Tarun Sukhadiya
Date : March 29 2020, 07:55 AM
it fixes the issue DrawerLayout should have at most two views. Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer.
See documentation
code :
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/appbar" 
            layout="@layout/app_bar_main"/>

        <include layout="@layout/app_bar_main_search"
            android:visibility="gone"/>

        <include
            layout="@layout/main_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/appbar"/>

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:visibility="gone"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
CSS behaving strangely

CSS behaving strangely


By : Mauricio Valverde
Date : March 29 2020, 07:55 AM
wish of those help Apply vertical-align:top for inline-block element, because the default alignment is baseline. It will resolve the issue.
code :
.propertyOverview {
   height: 430px;
   width: 357px;
   margin-right: 10px;
   margin-top: 15px;
   background-color: white;
   display: inline-block;
   vertical-align:top; /* Added this one for alignment */
   border: solid 1px #E8E8E8;
   border-radius: 5px;
   -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
  }
Related Posts Related Posts :
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • ShareActionProvider icon in actionbar
  • How to open a custom attachment using an Android app?
  • Unable to add column dynamically into the sqlite table
  • android persistence activity which never stop
  • The Google Play services resources were not found. Check your project configuration to ensure that the resources are inc
  • How to select files from google drive in android?
  • Run a AsyncTask every 10 seconds until cancelled
  • Blur on touch. Android application
  • NDK Android - Can't build ARMv5 and V7 at the same time
  • Android development with Eclipse clean and build
  • How to set Different Key Background for every Key in Android Custom Keyboard
  • Face recognition using OpenCV in android?
  • Tumblr API - Jumblr for Android [OAuthConnectionException]
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org