Example usage for android.widget ListView ListView

List of usage examples for android.widget ListView ListView

Introduction

In this page you can find the example usage for android.widget ListView ListView.

Prototype

public ListView(Context context) 

Source Link

Usage

From source file:edu.byu.scriptures.controller.fragment.RestartableListFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *//*from   w  w  w  .  j  a v a  2s .  c om*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    tv.setTextSize(18);

    int padding = ((MainActivity) getActivity()).getMetricsManager().dpToRawPixels(20);

    tv.setPadding(padding, 0, padding, 0);
    tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_normal));
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    ListView lv = new ListView(getActivity());
    int troughPadding = ((MainActivity) getActivity()).getMetricsManager().getTroughPadding();

    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setPadding(troughPadding, 0, troughPadding, 0);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.xalops.spotifystreamer.fragments.SearchListFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *///from   w w w  . j a  v a  2 s . c  o m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();
    FrameLayout root = new FrameLayout(context);

    //QUICK Inflate from XML file

    //inflater.inflate(R.layout.search_list_detail, root);
    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    RelativeLayout rlayout = new RelativeLayout(context);

    EditText et = new EditText(getActivity());
    et.setId(INTERNAL_SEARCH_FIELD_ID);
    et.setSingleLine(true);
    et.setInputType(InputType.TYPE_CLASS_TEXT);
    et.setImeOptions(EditorInfo.IME_ACTION_DONE);
    RelativeLayout.LayoutParams etRLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    etRLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    etRLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);
    RelativeLayout.LayoutParams lframeRLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    lframeRLayoutParams.addRule(RelativeLayout.BELOW, INTERNAL_SEARCH_FIELD_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    rlayout.addView(et, etRLayoutParams);
    rlayout.addView(lframe, lframeRLayoutParams);
    root.addView(rlayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.github.michalbednarski.intentslab.valueeditors.framework.CreateNewDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mListView = new ListView(getActivity());
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/* ww  w.j a v  a2 s  .c om*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CreatorOption option = (CreatorOption) mListView.getItemAtPosition(position);
            option.onOptionSelected(new EditorRedirect() {

                @Override
                public Context getContext() {
                    return getActivity();
                }

                @Override
                public void runEditorInActivity(Intent intent, Context context) {
                    throw new RuntimeException("Not yet implemented");
                }

                @Override
                public void runEditorInDialogFragment(ValueEditorDialogFragment editor, Bundle args) {
                    FragmentManager fragmentManager = getFragmentManager();
                    if (args == null) {
                        args = new Bundle();
                    }
                    Bundle chooserArguments = getArguments();
                    args.putString(EXTRA_KEY, chooserArguments.getString(EXTRA_KEY));
                    args.putString(Editor.EXTRA_TITLE, chooserArguments.getString(Editor.EXTRA_TITLE));
                    editor.setArguments(args);
                    editor.setTargetFragment(getTargetFragment(), 0);
                    editor.show(getActivity().getSupportFragmentManager(), getTag() + "Redirected");
                    dismiss();
                }

                @Override
                public void returnObject(Object object) {
                    sendResult(object);
                    dismiss();
                }

                @Override
                public void returnSandboxedObject(SandboxedObject object) {
                    throw new RuntimeException("Not yet implemented");
                }
            });
        }
    });
    checkAllCreatorsReady();
    return mListView;
}

From source file:by.istin.android.xcore.inherited.fragment.AdapterViewFragment.java

protected AdapterView<?> createDefaultAbstractView() {
    return new ListView(getActivity());
}

From source file:org.thialfihar.android.apg.ui.SelectPublicKeyFragment.java

/**
 * Copied from ListFragment and added EditText for search on top of list.
 * We do not use a custom layout here, because this breaks the progress bar functionality
 * of ListFragment./*from w  w w .jav a  2s.  com*/
 *
 * @param inflater
 * @param container
 * @param savedInstanceState
 * @return
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // Added for search view: linearLayout, mSearchView
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    mSearchView = new EditText(context);
    mSearchView.setId(SEARCH_ID);
    mSearchView.setHint(R.string.menu_search);
    mSearchView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_action_search),
            null, null, null);

    linearLayout.addView(mSearchView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    linearLayout.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    lframe.addView(linearLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:by.istin.android.xcore.fragment.AdapterViewFragment.java

protected AdapterView createDefaultAbstractView() {
    return new ListView(getActivity());
}

From source file:com.jaredrummler.materialspinner.MaterialSpinner.java

private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinner);
    int defaultColor = getTextColors().getDefaultColor();
    backgroundColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_background_color, Color.WHITE);
    textColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_text_color, defaultColor);
    arrowColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_arrow_tint, textColor);
    hideArrow = typedArray.getBoolean(R.styleable.MaterialSpinner_ms_hide_arrow, false);
    typedArray.recycle();/* w w w  . java2s  .c o m*/

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);

    boolean rtl = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Configuration config = getResources().getConfiguration();
        rtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        if (rtl) {
            setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            setTextDirection(View.TEXT_DIRECTION_RTL);
        }
    }

    Resources resources = getResources();
    int left, right, bottom, top;
    left = right = bottom = top = resources.getDimensionPixelSize(R.dimen.ms__padding_top);
    if (rtl) {
        right = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    } else {
        left = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    }

    setClickable(true);
    setPadding(left, top, right, bottom);
    setBackgroundResource(R.drawable.ms__selector);

    if (!hideArrow) {
        arrowDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ms__arrow));
        DrawableCompat.setTint(arrowDrawable, arrowColor);
        if (rtl) {
            setCompoundDrawablesWithIntrinsicBounds(arrowDrawable, null, null, null);
        } else {
            setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null);
        }
    }

    listView = new ListView(context);
    listView.setId(getId());
    listView.setDivider(null);
    listView.setItemsCanFocus(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= selectedIndex && position < adapter.getCount()) {
                position++;
            }
            selectedIndex = position;
            nothingSelected = false;
            Object item = adapter.get(position);
            adapter.notifyItemSelected(position);
            setText(item.toString());
            collapse();
            if (onItemSelectedListener != null) {
                //noinspection unchecked
                onItemSelectedListener.onItemSelected(MaterialSpinner.this, position, id, item);
            }
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(16);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drop_down_shadow));
    }

    if (backgroundColor != Color.WHITE) { // default color is white
        setBackgroundColor(backgroundColor);
    }
    if (textColor != defaultColor) {
        setTextColor(textColor);
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            if (nothingSelected && onNothingSelectedListener != null) {
                onNothingSelectedListener.onNothingSelected(MaterialSpinner.this);
            }
            if (!hideArrow) {
                animateArrow(false);
            }
        }
    });
}

From source file:org.telegram.ui.ChannelUsersActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (type == 0) {
        actionBar.setTitle(LocaleController.getString("ChannelBlockedUsers", R.string.ChannelBlockedUsers));
    } else if (type == 1) {
        actionBar.setTitle(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators));
    } else if (type == 2) {
        actionBar.setTitle(LocaleController.getString("ChannelMembers", R.string.ChannelMembers));
    }// ww w . ja  v a 2s  .c  om
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();

    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    emptyView = new EmptyTextProgressView(context);
    if (type == 0) {
        if (isMegagroup) {
            emptyView.setText(LocaleController.getString("NoBlockedGroup", R.string.NoBlockedGroup));
        } else {
            emptyView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
        }
    }
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    final ListView listView = new ListView(context);
    listView.setEmptyView(emptyView);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setDrawSelectorOnTop(true);
    listView.setAdapter(listViewAdapter = new ListAdapter(context));
    listView.setVerticalScrollbarPosition(
            LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (type == 2) {
                if (isAdmin) {
                    if (i == 0) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("returnAsResult", true);
                        args.putBoolean("needForwardCount", false);
                        args.putBoolean("allowUsernameSearch", false);
                        args.putString("selectAlertString",
                                LocaleController.getString("ChannelAddTo", R.string.ChannelAddTo));
                        ContactsActivity fragment = new ContactsActivity(args);
                        fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
                            @Override
                            public void didSelectContact(TLRPC.User user, String param) {
                                MessagesController.getInstance().addUserToChat(chatId, user, null,
                                        param != null ? Utilities.parseInt(param) : 0, null,
                                        ChannelUsersActivity.this);
                            }
                        });
                        presentFragment(fragment);
                    } else if (!isPublic && i == 1) {
                        presentFragment(new GroupInviteActivity(chatId));
                    }
                }

            } else if (type == 1) {
                if (isAdmin) {
                    if (isMegagroup && (i == 1 || i == 2)) {
                        TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
                        if (chat == null) {
                            return;
                        }
                        boolean changed = false;
                        if (i == 1 && !chat.democracy) {
                            chat.democracy = true;
                            changed = true;
                        } else if (i == 2 && chat.democracy) {
                            chat.democracy = false;
                            changed = true;
                        }
                        if (changed) {
                            MessagesController.getInstance().toogleChannelInvites(chatId, chat.democracy);
                            int count = listView.getChildCount();
                            for (int a = 0; a < count; a++) {
                                View child = listView.getChildAt(a);
                                if (child instanceof RadioCell) {
                                    int num = (Integer) child.getTag();
                                    ((RadioCell) child).setChecked(
                                            num == 0 && chat.democracy || num == 1 && !chat.democracy, true);
                                }
                            }
                        }
                        return;
                    }
                    if (i == participantsStartRow + participants.size()) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("returnAsResult", true);
                        args.putBoolean("needForwardCount", false);
                        args.putBoolean("allowUsernameSearch", true);
                        /*if (isMegagroup) {
                        args.putBoolean("allowBots", false);
                        }*/
                        args.putString("selectAlertString", LocaleController
                                .getString("ChannelAddUserAdminAlert", R.string.ChannelAddUserAdminAlert));
                        ContactsActivity fragment = new ContactsActivity(args);
                        fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
                            @Override
                            public void didSelectContact(TLRPC.User user, String param) {
                                setUserChannelRole(user, new TLRPC.TL_channelRoleEditor());
                            }
                        });
                        presentFragment(fragment);
                        return;
                    }
                }
            }
            TLRPC.ChannelParticipant participant = null;
            if (i >= participantsStartRow && i < participants.size() + participantsStartRow) {
                participant = participants.get(i - participantsStartRow);
            }
            if (participant != null) {
                Bundle args = new Bundle();
                args.putInt("user_id", participant.user_id);
                presentFragment(new ProfileActivity(args));
            }
        }
    });

    if (isAdmin || isMegagroup && type == 0) {
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (getParentActivity() == null) {
                    return false;
                }
                TLRPC.ChannelParticipant participant = null;
                if (i >= participantsStartRow && i < participants.size() + participantsStartRow) {
                    participant = participants.get(i - participantsStartRow);
                }
                if (participant != null) {
                    final TLRPC.ChannelParticipant finalParticipant = participant;
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    CharSequence[] items = null;
                    if (type == 0) {
                        items = new CharSequence[] { LocaleController.getString("Unblock", R.string.Unblock) };
                    } else if (type == 1) {
                        items = new CharSequence[] { LocaleController.getString("ChannelRemoveUserAdmin",
                                R.string.ChannelRemoveUserAdmin) };
                    } else if (type == 2) {
                        items = new CharSequence[] {
                                LocaleController.getString("ChannelRemoveUser", R.string.ChannelRemoveUser) };
                    }
                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (i == 0) {
                                if (type == 0) {
                                    participants.remove(finalParticipant);
                                    listViewAdapter.notifyDataSetChanged();
                                    TLRPC.TL_channels_kickFromChannel req = new TLRPC.TL_channels_kickFromChannel();
                                    req.kicked = false;
                                    req.user_id = MessagesController.getInputUser(finalParticipant.user_id);
                                    req.channel = MessagesController.getInputChannel(chatId);
                                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                        @Override
                                        public void run(TLObject response, TLRPC.TL_error error) {
                                            if (response != null) {
                                                final TLRPC.Updates updates = (TLRPC.Updates) response;
                                                MessagesController.getInstance().processUpdates(updates, false);
                                                if (!updates.chats.isEmpty()) {
                                                    AndroidUtilities.runOnUIThread(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            TLRPC.Chat chat = updates.chats.get(0);
                                                            MessagesController.getInstance()
                                                                    .loadFullChat(chat.id, 0, true);
                                                        }
                                                    }, 1000);
                                                }
                                            }
                                        }
                                    });
                                } else if (type == 1) {
                                    setUserChannelRole(
                                            MessagesController.getInstance().getUser(finalParticipant.user_id),
                                            new TLRPC.TL_channelRoleEmpty());
                                } else if (type == 2) {
                                    MessagesController.getInstance().deleteUserFromChat(chatId,
                                            MessagesController.getInstance().getUser(finalParticipant.user_id),
                                            null);
                                }
                            }
                        }
                    });
                    showDialog(builder.create());
                    return true;
                } else {
                    return false;
                }
            }
        });
    }

    if (loadingUsers) {
        emptyView.showProgress();
    } else {
        emptyView.showTextView();
    }
    return fragmentView;
}

From source file:com.ehelp.home.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);// w w w. j  a  va 2s . c  o  m
    //fl.setBackgroundColor(0x666666);
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setGravity(Gravity.TOP);
    System.out.println(position);
    if (position == 0) {
        fl.removeAllViews();
        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
        mMapView = new MapView(getActivity());
        mMapView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));
        fl.addView(mMapView);
        mBaiduMap = mMapView.getMap();
        // ??
        mBaiduMap.setMyLocationEnabled(true);
        // ??
        mLocClient = new LocationClient(getActivity());
        mLocClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true);// gps
        option.setCoorType("bd09ll"); // ??
        option.setScanSpan(1000);
        mLocClient.setLocOption(option);
        mLocClient.start();
        int count = mMapView.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = mMapView.getChildAt(i);
            if (child instanceof ZoomControls || child instanceof ImageView) {
                child.setVisibility(View.INVISIBLE);
            }
        }
        setLocation();
    } else if (position == 1) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 2, eventCache);
        queList.setAdapter(que);
        queList.setDividerHeight(20);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), recievesos_map.class);
                int eventid = events.get(index).getEventId();
                intent.putExtra(EXTRA_MESSAGE, eventid);
                startActivity(intent);
            }
        });
    } else if (position == 2) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        //queList.setBackgroundColor(0x666666);
        //queList.setAlpha(125);
        queList.setDividerHeight(20);
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 1, eventCache);
        queList.setAdapter(que);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), recieve_help_ans_map.class);
                intent.putExtra(EXTRA_MESSAGE, events.get(index));
                startActivity(intent);
            }
        });
    } else if (position == 3) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 0, eventCache);
        queList.setAdapter(que);
        queList.setDividerHeight(20);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), QuestionDetail.class);
                intent.putExtra("qusetiondatail", events.get(index));
                startActivity(intent);
            }
        });
    }
    return fl;
}

From source file:com.github.jvanhie.discogsscrobbler.ReleaseListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //check if the user wants to enable discogs support, if not, stop here
    if (!PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("enable_discogs", true)) {
        View emptyView = inflater.inflate(R.layout.fragment_empty, container, false);
        ((TextView) emptyView.findViewById(R.id.empty_heading)).setText("Discogs not enabled");
        ((TextView) emptyView.findViewById(R.id.empty_text)).setText(
                "Cannot display your collection without Discogs support, enable Discogs in the settings menu if you'd like to use this feature");
        mCallbacks.onAdapterSet();//from   ww  w  .j av a2 s. c  o m
        return emptyView;
    }

    String layout = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("collection_view",
            "");
    if (layout.equals("list")) {
        //setup list view
        mList = new ListView(getActivity());
        mList.setId(android.R.id.list);
    } else {
        mList = new GridView(getActivity());
        mList.setId(android.R.id.list);
        mGrid = true;
    }

    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            onListItemClick(view, i, l);
        }
    });

    mList.setFastScrollEnabled(true);

    //create superframe for adding list and empty view
    FrameLayout superFrame = new FrameLayout(getActivity());
    FrameLayout.LayoutParams layoutparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    superFrame.setLayoutParams(layoutparams);
    View emptyView = inflater.inflate(R.layout.fragment_empty, container, false);
    mEmptyHeading = ((TextView) emptyView.findViewById(R.id.empty_heading));
    mEmptyHeading.setText("Empty collection");
    mEmptyText = ((TextView) emptyView.findViewById(R.id.empty_text));
    mEmptyText.setText(
            "Your collection appears to be empty, if this isn't an error, start by adding some releases via the search function or online");

    /*initialize list with local discogs collection*/
    if (mDiscogs == null)
        mDiscogs = Discogs.getInstance(getActivity());

    loadList();

    if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("collection_auto_refresh",
            true)) {
        //do a background call to update the discogs collection if necessary
        checkOnlineCollection();
    }

    superFrame.addView(emptyView);
    mList.setEmptyView(emptyView);
    superFrame.addView(mList);

    return superFrame;
}