Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

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

Prototype

public TextView(Context context) 

Source Link

Usage

From source file:cc.metapro.openct.customviews.DuringDialog.java

private void setViews(GridLayout gridLayout) {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 6; j++) {
            final int week = i * 6 + j + 1;
            final TextView textView = new TextView(getActivity());
            textView.setText(week + gridLayout.getContext().getString(R.string.week));
            textView.setGravity(Gravity.CENTER);
            if (DURING[week]) {
                textView.setBackground(//from w  ww. j  a  v a2s . c  o m
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_blue));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
            } else {
                textView.setBackground(
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_grey));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.material_grey));
            }

            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DURING[week] = !DURING[week];
                }
            });
            GridLayout.Spec row = GridLayout.spec(i, 1, 1);
            GridLayout.Spec col = GridLayout.spec(j, 1, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
            gridLayout.addView(textView, params);
            selections[i][j] = textView;
        }
    }
}

From source file:com.sintech.RunningBus.java

public void initBusStation() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    String linename = sp.getString("lastLine", "");
    if (linename.equals("")) {
        Log.d("DBG", "initBusStation no line");
        return;/*  ww  w. jav  a2 s . c  o m*/
    }
    String js = sp.getString(linename, "{'name':'" + linename + "','stations':[],'stationDn':[]}");
    try {
        JSONObject jsonObject = new JSONObject(js);
        JSONArray array = jsonObject.getJSONArray("stations");
        TextView busname = (TextView) findViewById(R.id.IdBusname);
        busname.setText(jsonObject.getString("name"));
        LinearLayout ll = (LinearLayout) findViewById(R.id.IdStations);
        for (int i = 0; i < array.length(); i++) {
            String stInfo = array.getString(i);
            TextView station = new TextView(this);
            station.setText(stInfo.split("=")[0]);
            ll.addView(station);
        }
    } catch (Exception e) {
    }
}

From source file:at.flack.SMSMainActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_sms_main, container, false);

    contactNameMap = new ContactNameMap(getActivity());

    contactList = (ListView) rootView.findViewById(R.id.listviewsms);

    TextView padding = new TextView(getActivity());
    padding.setHeight(10);//  w  w  w. j  av  a  2s  .c  o  m
    contactList.addHeaderView(padding);
    contactList.setHeaderDividersEnabled(false);
    contactList.addFooterView(padding, null, false);
    contactList.setFooterDividersEnabled(false);

    swipe = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
    swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            if (getActivity() instanceof MainActivity)
                ((MainActivity) getActivity()).updateSMSContacts();
        }
    });
    contactList.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int topRowVerticalPosition = (contactList == null || contactList.getChildCount() == 0) ? 0
                    : contactList.getChildAt(0).getTop();
            swipe.setEnabled(topRowVerticalPosition >= 0);
        }
    });

    progressbar = rootView.findViewById(R.id.load_screen);
    if (MainActivity.getContacts() == null)
        progressbar.setVisibility(View.VISIBLE);

    updateContacts((MainActivity) getActivity());
    contactList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (MainActivity.getListItems() == null) {
                updateContacts((MainActivity) getActivity());
            }
            openMessageActivity(getActivity(), arg2 - 1);
        }

    });
    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.attachToListView(contactList);
    fab.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent qr = new Intent(getActivity(), NewSMSContactActivity.class);
            startActivityForResult(qr, 1);
        }
    });

    setRetainInstance(true);

    return rootView;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LocationObj.java

@Override
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from   w w  w .ja  v a 2 s .c om
    TextView valueTV = new TextView(context);
    NumberFormat df = DecimalFormat.getNumberInstance();
    df.setMaximumFractionDigits(5);
    df.setMinimumFractionDigits(5);

    String msg = "I'm at " + df.format(content.optDouble(COORD_LAT)) + ", "
            + df.format(content.optDouble(COORD_LONG));

    valueTV.setText(msg);
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);
}

From source file:cc.metapro.openct.myclass.TableFragment.java

private void addSeqViews() {
    final int DailyClasses = Integer
            .parseInt(PrefHelper.getString(getContext(), R.string.pref_daily_class_count, "12"));
    for (int i = 1; i <= DailyClasses; i++) {
        TextView textView = new TextView(getContext());
        textView.setText(i + "");
        textView.setGravity(Gravity.CENTER);
        textView.setMinHeight(Constants.CLASS_BASE_HEIGHT * Constants.CLASS_LENGTH);
        textView.setMaxHeight(Constants.CLASS_BASE_HEIGHT * Constants.CLASS_LENGTH);
        textView.setTextSize(10);//www .j  a v  a  2  s  .co  m
        mSeq.addView(textView);
    }
}

From source file:com.chess.genesis.dialog.GamePoolDialog.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("Game Pool Info");
    setBodyView(R.layout.dialog_gamepool);
    setButtonTxt(R.id.cancel, "Close");

    final TableLayout table = (TableLayout) findViewById(R.id.layout01);
    final LayoutParams layout = (TableRow.LayoutParams) findViewById(R.id.left).getLayoutParams();

    for (final PoolDataItem item : data) {
        final TableRow row = new TableRow(context);

        TextView txt = new TextView(context);
        txt.setLayoutParams(layout);//w  w w . jav  a 2s .  co m
        txt.setText(item.gametype);
        row.addView(txt);

        txt = new TextView(context);
        txt.setText(item.time);
        row.addView(txt);

        table.addView(row);
    }
}

From source file:com.sahana.geosmser.view.ReverseGeocoderView.java

public void initialUIComponent() {
    mTextView = new TextView(mContext);

    mEditText = new EditText(mContext);

    mButton = new Button(mContext);

    mTextView.setId(3);//ww  w .ja  va2  s .  co m
    mEditText.setId(1);
    mButton.setId(2);

    mTextView.setText("");
    mEditText.setHint("EX: ???");
    mButton.setText("");

    RelativeLayout.LayoutParams mTextLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams mEditLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams mButtonLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    mTextLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    mEditLayoutParams.addRule(BELOW, mTextView.getId());
    mButtonLayoutParams.addRule(RIGHT_OF, mEditText.getId());
    mButtonLayoutParams.addRule(ALIGN_BASELINE, mEditText.getId());

    mButton.setOnClickListener(getGeocoder);

    this.addView(mTextView, mTextLayoutParams);
    this.addView(mEditText, mEditLayoutParams);
    this.addView(mButton, mButtonLayoutParams);
}

From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName,
        final Uri uri, final LocalGeoJsonLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);/*from www.ja v  a2 s.  c  o  m*/

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);

    if (!bCreate) {
        //TODO: style for drawing
    }

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (bCreate) {
                        create(map, input.getText().toString(), uri);
                    } else {
                        layer.setName(input.getText().toString());
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.IMObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();// w  w  w.  j av a  2 s  .c  om
    TextView valueTV = new TextView(context);
    valueTV.setText("IM:" + content.optString(TEXT));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);
}

From source file:ca.farrelltonsolar.classic.DayLogCalendar.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    theView = inflater.inflate(R.layout.day_log_calendar, container, false);
    Bundle args = getArguments();/*from ww  w  .j a v  a 2 s.c  om*/
    int monthOffset = args != null ? args.getInt(ARG_MONTH) : 0;
    month = DateTime.now().minusMonths(monthOffset).withTimeAtStartOfDay().withDayOfMonth(1);
    adapter = new CalendarAdapter(this.getActivity(), month);
    GridView gridview = (GridView) theView.findViewById(R.id.gridview);
    gridview.setAdapter(adapter);
    gridview.setVelocityScale(5);

    TextView title = (TextView) theView.findViewById(R.id.title);
    title.setText(month.toString("MMMM yyyy"));
    View linearLayout = theView.findViewById(R.id.headerlayout);
    DateTime days = month;

    for (int i = 0; i < 7; i++) {
        int d = ((i + 6) % 7) + 1;
        days = days.withDayOfWeek(d);
        TextView aDay = new TextView(theView.getContext());
        aDay.setText(DateTimeFormat.forPattern("E").print(days));
        aDay.setGravity(Gravity.CENTER);
        aDay.setTextColor(Color.BLACK);
        aDay.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
        ((LinearLayout) linearLayout).addView(aDay);

    }

    return theView;
}