Example usage for android.widget TextView setId

List of usage examples for android.widget TextView setId

Introduction

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

Prototype

public void setId(@IdRes int id) 

Source Link

Document

Sets the identifier for this view.

Usage

From source file:org.sufficientlysecure.keychain.remote.ui.SelectPublicKeyFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getContext();
    FrameLayout root = new FrameLayout(context);

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

    ProgressBar progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);

    progressContainer.addView(progressBar, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

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

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

    TextView textView = new TextView(context);
    textView.setId(INTERNAL_EMPTY_VIEW_ID);
    textView.setGravity(Gravity.CENTER);

    listContainer.addView(textView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    LinearLayout innerListContainer = new LinearLayout(context);
    innerListContainer.setOrientation(LinearLayout.VERTICAL);

    mSearchView = new EditText(context);
    mSearchView.setId(android.R.id.input);
    mSearchView.setHint(R.string.menu_search);
    mSearchView.setCompoundDrawablesWithIntrinsicBounds(
            ContextCompat.getDrawable(context, R.drawable.ic_search_grey_24dp), null, null, null);

    innerListContainer.addView(mSearchView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    RecyclerView listView = new RecyclerView(context);
    listView.setId(INTERNAL_LIST_VIEW_ID);

    int padding = FormattingUtils.dpToPx(context, 8);
    listView.setPadding(padding, 0, padding, 0);
    listView.setClipToPadding(false);//from w ww . jav a 2  s.  c  o  m

    innerListContainer.addView(listView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    listContainer.addView(innerListContainer, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(listContainer, 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.tpb.projects.repo.fragments.RepoInfoFragment.java

private View getUserView(User u) {
    final LinearLayout layout = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.shard_user,
            mCollaborators, false);/*from w  w w . j av a  2  s  .  c o m*/
    layout.setId(View.generateViewId());
    final NetworkImageView avatar = ButterKnife.findById(layout, R.id.user_avatar);
    avatar.setId(View.generateViewId());
    avatar.setImageUrl(u.getAvatarUrl());
    avatar.setScaleType(ImageView.ScaleType.FIT_XY);
    final TextView login = ButterKnife.findById(layout, R.id.user_login);
    login.setId(View.generateViewId());
    if (u.getContributions() > 0) {
        login.setText(String.format(Locale.getDefault(), "%1$s\n%2$d", u.getLogin(), u.getContributions()));
    } else {
        login.setText(u.getLogin());
    }
    layout.setOnClickListener((v) -> {
        final Intent us = new Intent(getActivity(), UserActivity.class);
        us.putExtra(getString(R.string.intent_username), u.getLogin());
        UI.setDrawableForIntent(avatar, us);
        getActivity().startActivity(us,
                ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                        Pair.create(login, getString(R.string.transition_username)),
                        Pair.create(avatar, getString(R.string.transition_user_image))).toBundle());
    });
    return layout;
}

From source file:com.aboveware.abovegame.expandable.ExpandableListFragment.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.//w ww .  j  a va 2 s  . com
 * <p/>
 * <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
 * AbsListFragment. In particular, this is currently the only way to have the
 * built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FrameLayout root = new FrameLayout(getActivity());

    FrameLayout lframe = new FrameLayout(getActivity());
    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.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    ExpandableListView lv = new ExpandableListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    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));

    ListView.LayoutParams lp = new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    root.setLayoutParams(lp);

    return root;
}

From source file:com.dwdesign.tweetings.fragment.PullToRefreshListFragment.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./*from  w  ww.  ja  v  a 2s.c  o m*/
 * 
 * <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.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

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

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

    final 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));

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

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

    final 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));

    final PullToRefreshListView plv = new PullToRefreshListView(context);
    plv.setOnRefreshListener(this);
    mPullToRefreshListView = plv;

    final ListView lv = plv.getRefreshableView();
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(plv, 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:org.mariotaku.twidere.fragment.PullToRefreshListFragment.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.//from www . ja  va2  s  . c  o  m
 * 
 * <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.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

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

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

    final ProgressBar progress = new HoloProgressBar(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));

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

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

    final 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));

    final PullToRefreshListView plv = new PullToRefreshListView(context);
    plv.setOnRefreshListener(this);
    mPullToRefreshListView = plv;

    final ListView lv = plv.getRefreshableView();
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(plv, 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.example.android.MainActivity.java

/**Display JSON data in table format on the user interface of android app
 * by clicking on the button 'Start'*/
@Override// w w w . java2s . c o m
protected void onCreate(Bundle savedInstanceState) {
    /**
     * Declares TextView, Button and Tablelayout to retrieve the widgets 
     * from User Interface. Insert the TableRow into Table and set the 
     * gravity, font size  and id of table rows and columns.
     * 
     * Due to great amount of JSON data, 'for' loop method is used to insert 
     * the new rows and columns in the table. In each loop, each of rows and 
     * columns are set to has its own unique id. This purpose of doing this 
     * is to allows the user to read and write the text of specific rows and 
     * columns easily.
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    progress = new ProgressDialog(this);
    StartDisplay = (Button) findViewById(R.id.btnDisplay);
    profile = (TableLayout) findViewById(R.id.tableLayout1);
    profile.setStretchAllColumns(true);
    profile.bringToFront();

    for (int i = 1; i < 11; i++) {
        TableRow tr = new TableRow(this);
        TextView c1 = new TextView(this);
        TextView c2 = new TextView(this);
        c1.setId(i * 10 + 1);
        c1.setTextSize(12);
        c1.setGravity(Gravity.CENTER);
        c2.setId(i * 10 + 2);
        c2.setTextSize(12);
        c2.setGravity(Gravity.CENTER);
        tr.addView(c1);
        tr.addView(c2);
        tr.setGravity(Gravity.CENTER_HORIZONTAL);
        profile.addView(tr);
    }

    /**
    * onClick: Executes the DownloadWebPageTask once OnClick event occurs. 
    * When user click on the "Start" button, 
    * 1)the JSON data will be read from URL 
    * 2)Progress bar will be shown till all data is read and displayed in
    * table form. Once it reaches 100%, it will be dismissed. 
    * 
    * Progress Bar: The message of the progress bar is obtained from strings.xml.
    * New thread is created to handle the action of the progress bar. 
    */
    StartDisplay.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final String TAG = "MyActivity";
            progress.setMessage(getResources().getString(R.string.ProgressBar_message));
            progress.setCancelable(true);
            progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progress.setProgress(0);
            progress.setMax(100);
            progress.show();
            new Thread(new Runnable() {

                public void run() {
                    while (ProgressBarStatus < 100) {

                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            Log.e(TAG, Log.getStackTraceString(e));
                        }
                        progressBarbHandler.post(new Runnable() {
                            public void run() {
                                progress.setProgress(ProgressBarStatus);
                            }
                        });
                    }

                    if (ProgressBarStatus >= 100) {

                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            Log.e(TAG, Log.getStackTraceString(e));
                        }

                        progress.dismiss();
                    }
                }
            }).start();
            DownloadWebPageTask task = new DownloadWebPageTask();
            task.execute("http://private-ae335-pgserverapi.apiary.io/user/profile/234");
            StartDisplay.setClickable(false);
        }
    });

}

From source file:com.starwood.anglerslong.LicenseActivity.java

private void createTextView() {

    if (isCreateTextViewSet)
        return;//from  w w  w.j a v a2  s .  c  om

    // Get the linear layout and set the parameters
    LinearLayout ll = (LinearLayout) findViewById(R.id.profile_ll);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;

    TextView createLicense = new TextView(this);
    createLicense.setId(0);
    createLicense.setText(Html.fromHtml(getResources().getString(R.string.create_license_string)));
    createLicense.setPadding(70, 100, 70, 100);
    createLicense.setTextSize(18);
    ll.addView(createLicense, params);
    isCreateTextViewSet = true;
}

From source file:br.unb.mobileMedia.core.view.ExpandableListFragment.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/>/*from   w  ww. j  a  v  a 2 s .c om*/
 * <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.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FrameLayout root = new FrameLayout(getActivity());

    FrameLayout lframe = new FrameLayout(getActivity());
    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));

    ExpandableListView lv = new ExpandableListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, 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));

    ListView.LayoutParams lp = new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    root.setLayoutParams(lp);

    return root;
}

From source file:com.esri.arcgisruntime.sample.featurelayerupdateattributes.MainActivity.java

/**
 * Displays Callout/*from  w  w w.  j  ava  2 s. c om*/
 * @param title the text to show in the Callout
 */
private void showCallout(String title) {

    // create a text view for the callout
    RelativeLayout calloutLayout = new RelativeLayout(getApplicationContext());

    TextView calloutContent = new TextView(getApplicationContext());
    calloutContent.setId(R.id.textview);
    calloutContent.setTextColor(Color.BLACK);
    calloutContent.setTextSize(18);
    calloutContent.setPadding(0, 10, 10, 0);

    calloutContent.setText(title);

    RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relativeParams.addRule(RelativeLayout.RIGHT_OF, calloutContent.getId());

    // create image view for the callout
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageDrawable(
            ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_info_outline_black_18dp));
    imageView.setLayoutParams(relativeParams);
    imageView.setOnClickListener(new ImageViewOnclickListener());

    calloutLayout.addView(calloutContent);
    calloutLayout.addView(imageView);

    mCallout.setLocation(mMapView.screenToLocation(mClickPoint));
    mCallout.setContent(calloutLayout);
    mCallout.show();
}

From source file:com.todoroo.astrid.activity.ExpandableListFragment.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.
 *//*w w  w .  j  a  va2 s.  c o  m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FrameLayout root = new FrameLayout(getActivity());

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

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

    ListView.LayoutParams lp = new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    root.setLayoutParams(lp);

    return root;
}