Android code page

dismiss the keypad

rel1 = (RelativeLayout) findViewById(R.id.rel1);
rel1.setOnTouchListener(
                new View.OnTouchListener()
                {
                    @Override
                    public boolean onTouch(View view, MotionEvent ev) {
                        hideKeyboard(view);
                        return false;
                    }
                });
private void hideKeyboard(View v) {

        InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(MainActivity.INPUT_METHOD_SERVICE);

NetworkUtil

//String status = NetworkUtil.getConnectivityStatusString(context);

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
 * Created by k on 12/09/2016.
 */
public class NetworkUtil {
    public static int TYPE_WIFI = 1;
    public static int TYPE_MOBILE = 2;
    public static int TYPE_NOT_CONNECTED = 0;


    public static int getConnectivityStatus(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

getUrlContent

public   String getUrlContents(String theUrl) {
        StringBuilder content = new StringBuilder();
         try
        {
            URL url = new URL(theUrl);
            URLConnection urlConnection = url.openConnection();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                content.append(line + "\n");
            }
            bufferedReader.close();
        }

AsyncTask

private ProgressBar mProgressBar;
private Button mButton


        // On récupère les composants de notre layout
        mProgressBar = (ProgressBar) findViewById(R.id.pBAsync);
        mButton = (Button) findViewById(R.id.btnLaunch);

// On met un Listener sur le bouton
        mButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                BigCalcul calcul=new BigCalcul();
                calcul.execute();
            }
        });

public class BigCalcul extends AsyncTask

setOnClickListener Intent

imageButton = (ImageButton) findViewById(R.id.addButton);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               /* Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();*/
                Intent i = new Intent(getBaseContext(), FicheDevoir.class);
                 //i.putExtra("PersonID", "tutu");
                //startActivity(i);
                startActivityForResult(i, CHILD_ACTIVITY_CODE);

hideKeyboard function

    private void hideKeyboard(View v) {

        InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(FicheDevoir.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }

One simple trick we have to use is to make soft keyboard hidden at the app startup. As soon as the app starts the EditText gains the focus and the OS shows the keyboard covering the list items. If we don’t want this we can simply “move” the focus somewhere else:
1
2
	
android:focusable="true"
android:focusableInTouchMode="true"

Pages