Android LayoutInflater - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android LayoutInflater class.

This code example shows how to use the following methods:inflate
 
        @Override 
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv = (TextView) convertView;
            if (tv == null) {
                tv = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1, parent,
                        false); 
            } 
            ActivityInfo item = getItem(position);
            if (!TextUtils.isEmpty(item.nonLocalizedLabel)) {
                tv.setText(item.nonLocalizedLabel);
            } else { 
                tv.setText(item.labelRes);
            } 
            return tv;
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getContext
 
  private TextView textView;
 
  @Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    textView = new TextView(inflater.getContext());
    textView.setText("CustomFragment text view");
    return textView;
  } 
} 
7
CodeRank
This code example shows how to use the following methods:inflate
   * @see android.widget.CursorAdapter#newView(android.content.Context, 
   *      android.database.Cursor, ViewGroup) 
   */ 
  @Implementation 
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return mInflater.inflate(mLayout, parent, false);
  } 
 
  @Implementation 
  public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) {
    return mInflater.inflate(mDropDownLayout, parent, false);
  } 
 
  /** 
   * <p>Sets the layout resource of the item views.</p> 
   * 
   * @param layout the layout resources used to create item views 
   */ 
  @Implementation 
  public void setViewResource(int layout) {
7
CodeRank
This code example shows how to use the following methods:inflate, addView, removeView
    public void takeInputQueue(InputQueue.Callback callback) {
    } 
 
    @Override 
    public void setContentView(int layoutResID) {
        setContentView(getLayoutInflater().inflate(layoutResID, getDecorView()));
    } 
 
    @Override  
    public void setContentView(View view) {
        ViewGroup decorView = getDecorView();
        if (contentView != null) {
            shadowOf(contentView).callOnDetachedFromWindow();
            decorView.removeView(contentView);
 
        } 
        contentView = view;
 
        if (contentView != null) {
            if (contentView.getParent() != decorView && contentView != decorView) {

8
CodeRank
This code example shows how to use the following methods:getApplicationContext, from
public class OptionArrayAdapter extends ArrayAdapter<ContentValues> {
	protected LayoutInflater mFactory;
 
	public OptionArrayAdapter(Context context, int resource, List<ContentValues> objects) {
		super(context, resource, 0, objects);
		mFactory = LayoutInflater.from(context.getApplicationContext());
	} 
 
	@Override 
	public View getView(int position, View convertView, ViewGroup parent) {
 
		if (convertView == null) {
			convertView = mFactory.inflate(android.R.layout.simple_spinner_item, null);
		} 
 
		setValues(convertView, position);
 
		return convertView;
	} 
 
7
CodeRank
This code example shows how to use the following methods:inflate
	protected void setupView(Context context, final ViewGroup parent) {
		 
		// inflate our custom layout into parent 
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(R.layout.balloon_overlay_example2, parent);
		 
		// setup our fields 
		title = (TextView) v.findViewById(R.id.balloon_item_title);
		snippet = (TextView) v.findViewById(R.id.balloon_item_snippet);
		image = (ImageView) v.findViewById(R.id.balloon_item_image);
 
	} 
 
	@Override 
	protected void setBalloonData(CustomOverlayItem item, ViewGroup parent) {
		 
		// map our custom item data to fields 
		title.setText(item.getTitle());
		snippet.setText(item.getSnippet());
7
CodeRank
This code example shows how to use the following methods:inflate
 
        @Override 
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv = (TextView) convertView;
            if (tv == null) {
                tv = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1, parent,
                        false); 
            } 
            ActivityInfo item = getItem(position);
            if (!TextUtils.isEmpty(item.nonLocalizedLabel)) {
                tv.setText(item.nonLocalizedLabel);
            } else { 
                tv.setText(item.labelRes);
            } 
            return tv;
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getApplicationContext, from
    private PackageManager pm;
 
    public RegisteredAppsAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);
 
        mInflater = LayoutInflater.from(context);
        pm = context.getApplicationContext().getPackageManager();
    } 
 
    @Override 
    public void bindView(View view, Context context, Cursor cursor) {
        TextView text = (TextView) view.findViewById(R.id.api_apps_adapter_item_name);
        ImageView icon = (ImageView) view.findViewById(R.id.api_apps_adapter_item_icon);
 
        String packageName = cursor.getString(cursor.getColumnIndex(ApiApps.PACKAGE_NAME));
        if (packageName != null) {
            // get application name 
            try { 
                ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
 
6
CodeRank
This code example shows how to use the following methods:inflate
     * Create a new item view that can be re-bound to other item data later. 
     * 
     * @return The new item view 
     */ 
    public MenuView.ItemView createItemView(ViewGroup parent) {
        return (MenuView.ItemView) mSystemInflater.inflate(mItemLayoutRes, parent, false);
    } 
 
    /** 
     * Prepare an item view for use. See AdapterView for the basic idea at work here. 
     * This may require creating a new item view, but well-behaved implementations will 
     * re-use the view passed as convertView if present. The returned view will be populated 
     * with data from the item parameter. 
     * 
     * @param item Item to present 
     * @param convertView Existing view to reuse 
     * @param parent Intended parent view - use for inflation. 
     * @return View that presents the requested menu item 
     */ 
    public View getItemView(MenuItemImpl item, View convertView, ViewGroup parent) {
7
CodeRank
This code example shows how to use the following methods:inflate
        mShortcutRequested = savedState.getBoolean(KEY_SHORTCUT_REQUESTED);
    } 
 
    @Override 
    protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
        super.onCreateView(inflater, container);
        if (mCreateContactEnabled) {
            getListView().addHeaderView(inflater.inflate(R.layout.create_new_contact, null, false));
        } 
    } 
 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (position == 0 && mCreateContactEnabled) {
            mListener.onCreateNewContactAction();
        } else { 
            super.onItemClick(parent, view, position, id);
        } 
    } 
 
6
CodeRank

Related Android LayoutInflater Questions & Answers:

Other Android LayoutInflater Examples

45:		public View getView(int position, View convertView, ViewGroup parent) { 
46:	        if (convertView == null) {
47:	        	LayoutInflater mInflater = (LayoutInflater)
48:	                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
49:	            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
-
45:		public View getView(int position, View convertView, ViewGroup parent) { 
46:	        if (convertView == null) {
47:	        	LayoutInflater mInflater = (LayoutInflater)
48:	                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
49:	            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
-
63:		public View getDropDownView(int position, View convertView, ViewGroup parent) {
64:			if (convertView == null) {
65:	        	LayoutInflater mInflater = (LayoutInflater)
66:	                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
67:	            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
-
63:		public View getDropDownView(int position, View convertView, ViewGroup parent) {
64:			if (convertView == null) {
65:	        	LayoutInflater mInflater = (LayoutInflater)
66:	                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
67:	            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);

Read More

10:	
11:		@Override
12:		public View onCreateView(LayoutInflater inflater, ViewGroup container,
13:				Bundle savedInstanceState) {
14:

Read More

10:	
11:		@Override
12:		public View onCreateView(LayoutInflater inflater, ViewGroup container,
13:				Bundle savedInstanceState) {
14:

Read More

1:	public View onCreateView(LayoutInflater inflater, ViewGroup container,
2:	        Bundle savedInstanceState) {
3:	    ...

Read More

See Code Examples for Android LayoutInflater Methods: