Example usage for android.view LayoutInflater from

List of usage examples for android.view LayoutInflater from

Introduction

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

Prototype

public static LayoutInflater from(Context context) 

Source Link

Document

Obtains the LayoutInflater from the given context.

Usage

From source file:ee.ioc.phon.android.speak.Utils.java

public static AlertDialog getTextEntryDialog(Context context, String title, String initialText,
        final ExecutableString ex) {
    final View textEntryView = LayoutInflater.from(context).inflate(R.layout.alert_dialog_text_entry, null);
    final EditText et = (EditText) textEntryView.findViewById(R.id.url_edit);
    et.setText(initialText);//from w w  w .  ja v  a 2 s  . co m
    return new AlertDialog.Builder(context).setTitle(title).setView(textEntryView)
            .setPositiveButton(R.string.buttonOk, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ex.execute(et.getText().toString());
                }
            }).setNegativeButton(R.string.buttonCancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            }).create();
}

From source file:android.support.widget.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    int width = 0;

    int count = adapter.getCount();
    if (count > 1 && count <= 4) {
        width = getResources().getDisplayMetrics().widthPixels / count;
    }//w ww .ja  v  a 2s .c  o  m

    for (int i = 0; i < count; i++) {
        View tabView = null;
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (width != 0) {
            tabView.setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (tabTitleView != null) {
            tabTitleView.setText(adapter.getPageTitle(i));
        }
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

static View inflateLayoutByName(Context context, String name) {
    final int id = getResourceIdByName(context, "layout", name);
    if (id == 0) {
        return null;
    }/*from  www . ja v a2s  .c  o  m*/

    final View view = LayoutInflater.from(context).inflate(id, null);
    return view;
}

From source file:cm.aptoide.pt.ManageRepo.java

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

    LayoutInflater li = LayoutInflater.from(this);

    switch (item.getItemId()) {
    case ADD_REPO:
        View view = li.inflate(R.layout.addrepo, null);

        final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
        final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

        final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
        final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

        final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
        sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sec_user.setEnabled(true);
                    sec_pwd.setEnabled(true);
                } else {
                    sec_user.setEnabled(false);
                    sec_pwd.setEnabled(false);
                }/*from w  w  w  . j  a v a  2 s  . co  m*/
            }
        });

        Builder p = new AlertDialog.Builder(this).setView(view);
        alrt = p.create();
        alrt.setIcon(android.R.drawable.ic_menu_add);
        alrt.setTitle("Add new repository");

        alrt.setButton("Add", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Message msg = new Message();
                EditText uri = (EditText) alrt.findViewById(R.id.edit_uri);
                String uri_str = uri.getText().toString();
                sec_msg.setVisibility(View.GONE);
                sec_msg2.setVisibility(View.GONE);
                if (sec.isChecked()) {
                    String user = sec_user.getText().toString();
                    String pwd = sec_pwd.getText().toString();
                    int result = checkServer(uri_str, user, pwd);
                    if (result == 200) {
                        msg.obj = 0;
                        db.addServer(uri_str);
                        db.addLogin(user, pwd, uri_str);
                        change = true;
                        redraw();
                    } else if (result == 401) {
                        sec_msg2.setText("Login is wrong");
                        sec_msg2.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    } else {
                        sec_msg.setText("Can't connect to server");
                        sec_msg.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    }
                } else {
                    int result = checkServer(uri_str, null, null);
                    if (result == 200) {
                        msg.obj = 0;
                        db.addServer(uri_str);
                        change = true;
                        redraw();
                    } else if (result == 401) {
                        sec_msg2.setText("Login required");
                        sec_msg2.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    } else {
                        sec_msg.setText("Can't connect to server");
                        sec_msg.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    }
                }
                new_repo.sendMessage(msg);
            }
        });

        alrt.setButton2("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                alrt.dismiss();
            }
        });
        alrt.show();
        break;

    case REM_REPO:
        final Vector<String> rem_lst = new Vector<String>();
        CharSequence[] b = new CharSequence[server_lst.size()];
        for (int i = 0; i < server_lst.size(); i++) {
            b[i] = server_lst.get(i).uri;
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Chose repository to remove");
        builder.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
        builder.setMultiChoiceItems(b, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
                if (isChecked) {
                    rem_lst.addElement(server_lst.get(whichButton).uri);
                } else {
                    rem_lst.removeElement(server_lst.get(whichButton).uri);
                }
            }
        });
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                db.removeServer(rem_lst);
                change = true;
                redraw();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
        break;

    case EDIT_REPO:
        CharSequence[] b2 = new CharSequence[server_lst.size()];
        for (int i = 0; i < server_lst.size(); i++) {
            b2[i] = server_lst.get(i).uri;
        }

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle("Chose repository to edit");
        builder2.setIcon(android.R.drawable.ic_menu_edit);
        builder2.setSingleChoiceItems(b2, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                updt_repo = server_lst.get(which).uri;
            }
        });
        builder2.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                editRepo(updt_repo);
                return;
            }
        });
        builder2.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        alert2 = builder2.create();
        alert2.show();
        break;
    }
    return super.onMenuItemSelected(featureId, item);
}

From source file:com.insthub.O2OMobile.Activity.D1_OrderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.d1_order_listview);

    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mRightText = (TextView) findViewById(R.id.top_view_right_text);
    mBack.setOnClickListener(new OnClickListener() {

        @Override//from   w  w w.j  a  v  a 2s  .co m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mTitle.setText(getString(R.string.order_detail));
    mRightText.setVisibility(View.VISIBLE);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mWidthPixels = dm.widthPixels;

    Intent intent = getIntent();
    mOrderId = intent.getIntExtra(ORDER_ID, 0);

    mHeaderView = LayoutInflater.from(this).inflate(R.layout.d1_order, null);
    mXListView = (XListView) findViewById(R.id.order_listview);
    mXListView.addHeaderView(mHeaderView);
    mXListView.setPullLoadEnable(false);
    mXListView.loadMoreHide();
    mXListView.setRefreshTime();
    mXListView.setXListViewListener(this, 1);
    mXListView.setAdapter(null);

    mOrderBtnCancel = (Button) findViewById(R.id.order_button_cancel);
    mOrderBtnOk = (Button) findViewById(R.id.order_button_ok);
    mOrderEmptyView = (ImageView) findViewById(R.id.order_empty_view);

    mOrderPlay = findViewById(R.id.order_play);
    mOrderPlayOrderView = (LinearLayout) findViewById(R.id.order_play_order_view);
    mOrderPlayOrderSn = (TextView) findViewById(R.id.order_play_order_sn);
    mOrderPlayOrderServiceType = (TextView) findViewById(R.id.order_play_order_service_type);
    mOrderPlayOrderLocation = (TextView) findViewById(R.id.order_play_order_location);
    mOrderPlayOrderPrice = (TextView) findViewById(R.id.order_play_order_price);
    mOrderPlayButtonView = (LinearLayout) findViewById(R.id.order_play_button_view);
    mOrderPlayOnline = (Button) findViewById(R.id.order_play_online);
    mOrderPlayOffline = (Button) findViewById(R.id.order_play_offline);
    mOrderPlayCancel = (Button) findViewById(R.id.order_play_cancel);

    mOrderEmployerAvatar = (RoundedWebImageView) mHeaderView.findViewById(R.id.order_employer_avatar);
    mOrderEmployerName = (TextView) mHeaderView.findViewById(R.id.order_employer_name);
    mOrderEmployerPhone = (ImageView) mHeaderView.findViewById(R.id.order_employer_phone);
    mOrderTime = (TextView) mHeaderView.findViewById(R.id.order_time);
    mOrderSn = (TextView) mHeaderView.findViewById(R.id.order_sn);
    mOrderServiceType = (TextView) mHeaderView.findViewById(R.id.order_service_type);
    mOrderAppointmentTime = (TextView) mHeaderView.findViewById(R.id.order_appointment_time);
    mOrderLocation = (TextView) mHeaderView.findViewById(R.id.order_location);
    mOrderPrice = (TextView) mHeaderView.findViewById(R.id.order_price);
    mOrderTransactionPriceView = (LinearLayout) mHeaderView.findViewById(R.id.order_transaction_price_view);
    mOrderTransactionPrice = (TextView) mHeaderView.findViewById(R.id.order_transaction_price);
    mOrderContentText = (TextView) mHeaderView.findViewById(R.id.order_content_text);
    mOrderContentVoiceView = (LinearLayout) mHeaderView.findViewById(R.id.order_content_voice_view);
    mOrderContentVoiceIcon = (ImageView) mHeaderView.findViewById(R.id.order_content_voice_icon);
    mOrderContentVoiceTime = (TextView) mHeaderView.findViewById(R.id.order_content_voice_time);
    mOrderStatusView = (LinearLayout) mHeaderView.findViewById(R.id.order_status_view);
    mOrderStatus = (TextView) mHeaderView.findViewById(R.id.order_status);
    mOrderStatusArrow = (ImageView) mHeaderView.findViewById(R.id.order_status_arrow);
    mOrderVisibleButtonView = mHeaderView.findViewById(R.id.order_visible_button_view);
    mOrderWaitView = (LinearLayout) mHeaderView.findViewById(R.id.order_wait_view);
    mOrderEmployeeCount = (TextView) mHeaderView.findViewById(R.id.order_employee_count);
    mOrderEmployeeView = (LinearLayout) mHeaderView.findViewById(R.id.order_employee_view);
    mOrderEmployeeAvatar = (RoundedWebImageView) mHeaderView.findViewById(R.id.order_employee_avatar);
    mOrderEmployeeName = (TextView) mHeaderView.findViewById(R.id.order_employee_name);
    mOrderEmployeePhone = (ImageView) mHeaderView.findViewById(R.id.order_employee_phone);
    mOrderCommentView = (LinearLayout) mHeaderView.findViewById(R.id.order_comment_view);
    mAcceptOrderTime = (TextView) mHeaderView.findViewById(R.id.accept_order_time);

    mRightText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(D1_OrderActivity.this, G0_ReportActivity.class);
            intent.putExtra("orderId", mOrderId);
            startActivity(intent);
        }
    });
    mOrderEmptyView.setOnClickListener(null);
    mOrderPlayOrderView.setOnClickListener(null);
    mOrderPlay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
            mOrderPlayOrderView.setVisibility(View.GONE);
            AnimationUtil.backAnimation(mOrderPlayButtonView);
            mOrderPlayButtonView.setVisibility(View.GONE);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mOrderPlay.setVisibility(View.GONE);
                    mOrderBtnCancel.setVisibility(View.VISIBLE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mOrderPlayOnline.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            payCode = ENUM_PAY_CODE.PAY_ONLINE;
            mOrderInfoModel.pay(mOrderId, ENUM_PAY_CODE.PAY_ONLINE.value());

        }
    });

    mOrderPlayOffline.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            payCode = ENUM_PAY_CODE.PAY_OFFLINE;
            mOrderInfoModel.pay(mOrderId, ENUM_PAY_CODE.PAY_OFFLINE.value());
        }
    });

    mOrderPlayCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
            mOrderPlayOrderView.setVisibility(View.GONE);
            AnimationUtil.backAnimation(mOrderPlayButtonView);
            mOrderPlayButtonView.setVisibility(View.GONE);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mOrderPlay.setVisibility(View.GONE);
                    mOrderBtnCancel.setVisibility(View.VISIBLE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mOrderStatusView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(D1_OrderActivity.this, D2_OrderHistoryActivity.class);
            intent.putExtra("order_id", mOrderId);
            startActivity(intent);
        }
    });

    mOrderInfoModel = new OrderInfoModel(this);
    mOrderInfoModel.addResponseListener(this);
    mOrderInfoModel.get(mOrderId);

}

From source file:com.actionbarsherlock.internal.widget.ScrollingTabContainerView.java

private IcsLinearLayout createTabLayout() {
    final IcsLinearLayout tabLayout = (IcsLinearLayout) LayoutInflater.from(getContext())
            .inflate(R.layout.abs__action_bar_tab_bar_view, null);
    tabLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    return tabLayout;
}

From source file:app.learning.fantaster.nhatkyhoctiengnhat.util.slidingtab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from w ww  . j a  v  a 2s .  c o  m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        CharSequence title = adapter.getPageTitle(i);
        tabTitleView.setText(title);
        tabTitleView.setGravity(Gravity.CENTER_HORIZONTAL);
        tabTitleView.setTextColor(Color.WHITE);
        tabView.setOnClickListener(tabClickListener);

        if (mDistributeEvenly) {
            tabView.setLayoutParams(layoutParams);
        }

        mTabStrip.addView(tabView);
    }
}

From source file:cm.aptoide.pt.RemoteInTab.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case UPDATE_REPO:
        final AlertDialog upd_alrt = new AlertDialog.Builder(this).create();
        if (!db.areServers()) {
            upd_alrt.setIcon(android.R.drawable.ic_dialog_alert);
            upd_alrt.setTitle("Empty");
            upd_alrt.setMessage(/*from   www.  j  ava 2  s  .co  m*/
                    "There are no enabled repositories in your list.\nPlease add repository or enable the ones you have!");
            upd_alrt.setButton("Ok", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });
        } else {
            upd_alrt.setIcon(android.R.drawable.ic_dialog_alert);
            upd_alrt.setTitle("Update repositories");
            upd_alrt.setMessage(
                    "Do you wish to update repositories?\nThis can take a while (WiFi is advised)...");
            upd_alrt.setButton("Yes", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    updateRepos();
                }
            });
            upd_alrt.setButton2("No", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    upd_alrt.dismiss();
                }
            });
        }
        upd_alrt.show();
        return true;
    case MANAGE_REPO:
        Intent i = new Intent(this, ManageRepo.class);
        startActivityForResult(i, NEWREPO_FLAG);
        return true;
    case SEARCH_MENU:
        onSearchRequested();
        return true;
    case ABOUT:
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.about, null);
        Builder p = new AlertDialog.Builder(this).setView(view);
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.icon);
        alrt.setTitle("APTOIDE");
        alrt.setButton("ChangeLog", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                Uri uri = Uri.parse("http://aptoide.com/changelog.html");
                startActivity(new Intent(Intent.ACTION_VIEW, uri));
            }
        });
        alrt.show();
        return true;
    case SETTINGS:
        Intent s = new Intent(RemoteInTab.this, Settings.class);
        s.putExtra("order", order_lst);
        startActivityForResult(s, SETTINGS_FLAG);
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.firesoft.member.Activity.C1_PublishOrderActivity.java

public void initData() {
    Date date = new Date();
    mTime.setText(mFormat.format(date));
    mTime.setOnClickListener(new View.OnClickListener() {

        @Override//from w w  w . ja v  a  2  s. co m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            CloseKeyBoard();
            LayoutInflater inflater = LayoutInflater.from(C1_PublishOrderActivity.this);
            final View timepickerview = inflater.inflate(R.layout.timepicker, null);
            ScreenInfo screenInfo = new ScreenInfo(C1_PublishOrderActivity.this);
            mWheelMain = new WheelMain(timepickerview);
            mWheelMain.screenheight = screenInfo.getHeight();
            Calendar calendar = Calendar.getInstance();
            try {
                calendar.setTime(mFormat.parse(mTime.getText().toString()));
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int min = calendar.get(Calendar.MINUTE);
            mWheelMain.initDateTimePicker(year, month, day, hour, min);
            new AlertDialog.Builder(C1_PublishOrderActivity.this).setTitle("")
                    .setView(timepickerview)
                    .setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            mTime.setText(mWheelMain.getTime());
                        }
                    }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).show();
        }
    });
}

From source file:atom.mobile.lib.slidedate.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from  w  w w .j  a  va  2 s . c om*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        // Used to get a reference to each tab's TextView in order to
        // update the text in setTabText().
        mTabTitleViews.put(i, tabTitleView);

        mTabStrip.addView(tabView);
    }
}