Example usage for android.view LayoutInflater inflate

List of usage examples for android.view LayoutInflater inflate

Introduction

In this page you can find the example usage for android.view LayoutInflater inflate.

Prototype

public View inflate(XmlPullParser parser, @Nullable ViewGroup root) 

Source Link

Document

Inflate a new view hierarchy from the specified xml node.

Usage

From source file:com.example.pyrkesa.frag.UserAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context1.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.user_list_item, null);
    }/*from   w  w  w  .  j a  va  2 s  .c  o m*/
    pos = position;
    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.contact);
    final TextView txtTitle = (TextView) convertView.findViewById(R.id.user_login);
    ImageButton imgDelete = (ImageButton) convertView.findViewById(R.id.delete);

    imgIcon.setImageResource(userItems.get(position).getIcon());
    txtTitle.setText(userItems.get(position).getTitle());
    imgDelete.setImageResource(userItems.get(position).getDelete());

    imgDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //Toast.makeText(context1,"ggffgfg",Toast.LENGTH_LONG).show();

            ModelFactory model = (ModelFactory) ModelFactory.getContext();
            if (model.user.type == 1) {
                new AlertDialog.Builder(v.getContext()).setTitle("Supprimer " + txtTitle.getText())
                        .setMessage("Voulez-vous supprimer cet utilisateur?")
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // continue with delete
                                new DeleteUser().execute(txtTitle.getText().toString());
                            }
                        }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // do nothing
                            }
                        }).setIcon(android.R.drawable.ic_dialog_alert).show();
            } else {
                new AlertDialog.Builder(v.getContext()).setTitle("Attention")
                        .setMessage("Opration interdite : Droits d'administration requis.").show();
            }

        }
    });

    return convertView;
}

From source file:com.chess.genesis.activity.GameListLocalFrag.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    initBaseContentFrag(container);//w  w w  .  j  ava 2s .com

    final View view = inflater.inflate(R.layout.fragment_gamelist_local, null);

    // set list adapters
    gamelist_adapter = new GameListAdapter(getActivity(), Enums.LOCAL_GAME, Enums.YOUR_TURN);

    final ListView gamelist_view = (ListView) view.findViewById(R.id.game_list);
    gamelist_view.setAdapter(gamelist_adapter);
    gamelist_view.setOnItemClickListener(this);

    // set empty view item
    final View empty = gamelist_adapter.getEmptyView(getActivity());
    ((ViewGroup) gamelist_view.getParent()).addView(empty);
    gamelist_view.setEmptyView(empty);

    registerForContextMenu(gamelist_view);

    return view;
}

From source file:com.radicaldynamic.groupinform.application.Collect.java

public void showCustomToast(String message) {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.toast_view, null);

    // Set the text in the view
    TextView tv = (TextView) view.findViewById(R.id.message);
    tv.setText(message);//w ww  .j av a 2  s  . c o  m

    Toast t = new Toast(this);
    t.setView(view);
    t.setDuration(Toast.LENGTH_SHORT);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
}

From source file:com.example.android.donebar.DoneButtonActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // BEGIN_INCLUDE (inflate_set_custom_view)
    // Inflate a "Done" custom action bar view to serve as the "Up" affordance.
    final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override//w  ww .j a v a 2s.c  o  m
        public void onClick(View v) {
            // "Done"
            finish();
        }
    });

    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView);
    // END_INCLUDE (inflate_set_custom_view)

    AsyncHttpClient client = new AsyncHttpClient();

    client.get("http://192.168.0.101:8080/AndroidRESTful2/webresources/com.erikchenmelbourne.entities.caller",
            new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, org.apache.http.Header[] headers,
                        org.json.JSONArray response) {
                    if (response != null) {
                        String string = response.toString();
                        try {
                            JSONArray jsonarray = new JSONArray(string);
                            Caller.jsonarraylist.clear();
                            populateArrayList(jsonarray, Caller.jsonarraylist);
                            /*for (int i = 0; i < Caller.jsonarraylist.size(); i++) {
                            Toast.makeText(getApplicationContext(), Caller.jsonarraylist.get(i).toString(), Toast.LENGTH_LONG).show();
                            }*/
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Toast.makeText(getApplicationContext(),
                                "Status Code: " + statusCode + " Data has been posted.", Toast.LENGTH_LONG)
                                .show();
                    }
                }

                @Override
                public void onFailure(int statusCode, org.apache.http.Header[] headers,
                        java.lang.Throwable throwable, org.json.JSONArray errorResponse) {
                    if (statusCode == 404) {
                        Toast.makeText(getApplicationContext(), "Requested resource not found.",
                                Toast.LENGTH_LONG).show();
                    } else if (statusCode == 500) {
                        Toast.makeText(getApplicationContext(), "Something went wrong at server end.",
                                Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(getApplicationContext(),
                                "Unexpected Error occurred. [Most common Error: Device might not be connected to Internet or remote server is not up and running]",
                                Toast.LENGTH_LONG).show();
                    }
                }
            });

    setContentView(R.layout.activity_done_button);
}

From source file:com.doomy.decode.ResultDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater mLayoutInflater = LayoutInflater.from(getActivity());
    View mView = mLayoutInflater.inflate(R.layout.view_result, null);

    TextView mTextViewFormat = (TextView) mView.findViewById(R.id.textViewFormat);
    TextView mTextViewContent = (TextView) mView.findViewById(R.id.textViewContent);

    if (mTitle.equals("EAN 13") && mMessage.startsWith("978")) {
        GetResponseTask mGetResponseTask = new GetResponseTask();
        mGetResponseTask.execute(mMessage);

        try {/*from ww  w  .java  2s  .c o m*/
            if (mGetResponseTask.get().equals("")) {
                mTitle = "ISBN";
                mTextViewContent.setText(mMessage);
            } else {
                mTitle = "ISBN";
                mMessage = mGetResponseTask.get();
                SpannableString mSpan = new SpannableString(mMessage);
                mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
                mTextViewContent.setText(mSpan);
                mTextViewContent.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        createURLIntent(makeURLSearch(mMessage));
                    }
                });
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    } else if (mTitle.equals("ISBN")) {
        if (!mMessage.startsWith("978")) {
            SpannableString mSpan = new SpannableString(mMessage);
            mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
            mTextViewContent.setText(mSpan);
            mTextViewContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    createURLIntent(makeURLSearch(mMessage));
                }
            });
        } else {
            mTextViewContent.setText(mMessage);
        }
    } else if (mMessage.startsWith("www") || mMessage.startsWith("http://")
            || mMessage.startsWith("https://")) {
        SpannableString mSpan = new SpannableString(mMessage);
        mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
        mTextViewContent.setText(mSpan);
        mTextViewContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createURLIntent(mMessage);
            }
        });
    } else {
        mTextViewContent.setText(mMessage);
    }

    if (mKey) {
        SimpleDateFormat mDateFormat = new SimpleDateFormat("dd/MM/yyyy-HH:mm");
        String mDate = mDateFormat.format(new Date());
        Scan mScan = new Scan(mTitle, mMessage, mDate);
        mDB.addOne(mScan);
    }

    mTextViewFormat.setText(mTitle);

    AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity(), Utils.setThemeDialog());

    mAlertBuilder.setTitle(getString(R.string.info)).setView(mView).setPositiveButton(getString(R.string.okay),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (mListener != null) {
                        mListener.onDialogPositiveClick(ResultDialogFragment.this);
                    }
                }
            });

    return mAlertBuilder.create();
}

From source file:com.example.android.donebar.DoneBarActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // BEGIN_INCLUDE (inflate_set_custom_view)
    // Inflate a "Done/Cancel" custom action bar view.
    final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_cancel, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w w . j  ava  2  s.  c o m*/
        public void onClick(View v) {
            // "Done"
            int id = generateId();
            EditText number = (EditText) findViewById(R.id.caller_phone_number);
            EditText information = (EditText) findViewById(R.id.caller_information);

            checkAvailability(id, number.getText().toString(), information.getText().toString());

            finish();
        }
    });
    customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // "Cancel"
            finish();
        }
    });

    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // END_INCLUDE (inflate_set_custom_view)

    setContentView(R.layout.activity_done_bar);
}

From source file:app.hacked.ProjectListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.project_list_fragment, null);

    return view;//from   www .j a v  a 2 s .co  m
}

From source file:com.fabioarias.ui.Search.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.search, null);
    View scanView = (View) view.findViewById(R.id.p2);
    searchField = (EditText) view.findViewById(R.id.editText1);
    setTouchNClick(view.findViewById(R.id.p1));
    setTouchNClick(scanView);//from  w  ww .j a  v  a 2  s  .  com
    searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView vv, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // BUSQUEDA POR CRITERIA
                search(searchField.getText().toString());
                return true;
            }
            return false;
        }
    });

    this.v = view;
    if (scan != null) {
        search(scan);
    }
    return view;
}

From source file:app.hacked.AddProjectFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.add_project_fragment, null);

    ((TextView) view.findViewById(R.id.Title)).setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));

    ProjectNameET = (EditText) view.findViewById(R.id.ProjectNameET);
    SynopsisET = (EditText) view.findViewById(R.id.SynopsisET);
    DescET = (EditText) view.findViewById(R.id.DescET);
    TeamMemberET = (EditText) view.findViewById(R.id.TeamMemberET);
    TechET = (EditText) view.findViewById(R.id.ProjectNameET);

    ((Button) view.findViewById(R.id.CancelButton)).setOnClickListener(new View.OnClickListener() {
        @Override/*from w  w w .  j  ava  2s  .c  o  m*/
        public void onClick(View view) {
            getActivity().finish();
        }
    });

    ((Button) view.findViewById(R.id.addProjectButton)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ProjectNameET.getText().toString().equals("")) {
                Toast.makeText(getActivity(), "A project needs a name for people to recognise!",
                        Toast.LENGTH_SHORT).show();
                return;
            }

            JSONObject post = new JSONObject();
            try {
                post.put("project_name", ProjectNameET.getText().toString());
                post.put("project_synopsis", SynopsisET.getText().toString());
                post.put("project_desc", DescET.getText().toString());
                post.put("project_team", TeamMemberET.getText().toString());
                post.put("project_tech", TechET.getText().toString());
                post.put("auth", API.md5(API.BETTER_THAN_NOTHING_STUFF_TO_PREVENT_INJECTION_ATTEMPTS
                        + ProjectNameET.getText().toString()));
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getActivity(),
                        "An Error Was encountered parsing the entered details: " + e.getMessage(),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,
                    "http://hackedioapp.networksaremadeofstring.co.uk/addproject.php", post,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            Log.e("response", response.toString());
                            try {
                                if (response.has("success") && response.getBoolean("success")) {
                                    Toast.makeText(getActivity(), "Project added successfully!",
                                            Toast.LENGTH_SHORT).show();

                                    if (getActivity().findViewById(R.id.ProjectDetails) != null) {
                                        Bundle arguments = new Bundle();
                                        arguments.putInt(ProjectDetailsFragment.PROJECTID,
                                                response.getInt("uuid"));
                                        arguments.putString(ProjectDetailsFragment.NAME,
                                                ProjectNameET.getText().toString());
                                        arguments.putString(ProjectDetailsFragment.SYNOPSIS,
                                                SynopsisET.getText().toString());
                                        arguments.putString(ProjectDetailsFragment.DESCRIPTION,
                                                DescET.getText().toString());
                                        arguments.putString(ProjectDetailsFragment.TECHNOLOGIES,
                                                TechET.getText().toString());
                                        arguments.putInt(ProjectDetailsFragment.POPULARITY, 1);
                                        arguments.putString(ProjectDetailsFragment.TEAMMEMBERS,
                                                TeamMemberET.getText().toString());
                                        arguments.putBoolean(ProjectDetailsFragment.ARG_2PANE, true);

                                        ProjectDetailsFragment fragment = new ProjectDetailsFragment();
                                        fragment.setArguments(arguments);
                                        fragment.setHasOptionsMenu(true);
                                        getActivity().getSupportFragmentManager().beginTransaction()
                                                .replace(R.id.ProjectDetails, fragment).commit();
                                    } else {
                                        getActivity().finish();

                                        Intent detailIntent = new Intent(getActivity(),
                                                ProjectDetailsActivity.class);
                                        detailIntent.putExtra(ProjectDetailsFragment.PROJECTID,
                                                response.getInt("uuid"));
                                        detailIntent.putExtra(ProjectDetailsFragment.NAME,
                                                ProjectNameET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.SYNOPSIS,
                                                SynopsisET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.DESCRIPTION,
                                                DescET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.TECHNOLOGIES,
                                                TechET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.POPULARITY, 1);
                                        detailIntent.putExtra(ProjectDetailsFragment.TEAMMEMBERS,
                                                TeamMemberET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.ARG_2PANE, true);
                                        startActivity(detailIntent);
                                    }
                                } else {
                                    String error = "";
                                    if (response.has("error"))
                                        error = ": " + response.getString("error");

                                    Toast.makeText(getActivity(), "An Error Was encountered" + error,
                                            Toast.LENGTH_SHORT).show();
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                Toast.makeText(getActivity(), "An Error Was encountered: " + e.getMessage(),
                                        Toast.LENGTH_SHORT).show();
                            }

                        }
                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Toast.makeText(getActivity(), "An Error Was encountered: " + error.getMessage(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    });

            queue.add(jsObjRequest);
        }
    });
    return view;
}

From source file:it.crs4.most.ehrlib.widgets.InnerArchetypeWidget.java

private void buildInnerArchetypeView() {
    LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.inner_archetype, null);

    _root_view = view;/*www .  j av  a  2 s.  co  m*/

    _archetype_layout = (LinearLayout) _root_view.findViewById(R.id.archetype_container);

    _title = (TextView) _root_view.findViewById(R.id.txt_archetype_title);

    addRemWidgets = (ImageView) _root_view.findViewById(R.id.image_toggle_widgets);
    addRemWidgets.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (areWidgetsVisible)
                removeWidgets();
            else
                addWidgets();

        }
    });

}