0

I began to learn Android development and can't perform a simple thing. I have an activity_login.xml which defines couples of widgets (TextViews, buttons, etc.) and I want to change textview size programmatically. I' m trying to use R.id but Eclipse don't see my text view. Here what i've tried. TextView in res/layout/activity_login.xml file:

<TextView
    android:id="@+id/login_text_view"
    android:layout_width="23"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button_log"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/button_sign_up"
    android:layout_marginTop="34dp"
    />

And here I'm trying to connect to it in my LoginActivity.java:

final TextView loginTextView = (TextView) findViewById(R.id.login_text_view);

The problem Eclipse don't see neither loginTextView nor other widgets in xml file.

Oleksandr Karaberov
  • 12,573
  • 10
  • 43
  • 70
  • try after `cleaning` the project. – Mohsin Naeem Dec 06 '12 at 16:39
  • Did you set the contentView() of your activity first? – codeMagic Dec 06 '12 at 16:39
  • 2
    try after Cleaning your project from Project->Clean on Eclipse IDE menu and also do a refresh and close or open because it may be possible you have some error in your xml layouts so R file is not generated. after that in your activity do CTRL+SHFT+O for importing your R instead of android.R – ρяσѕρєя K Dec 06 '12 at 16:40

2 Answers2

1

In your activity make sure you set the layout in onCreate() using setContentView(R.layout.activity_login)

Oleksandr Karaberov
  • 12,573
  • 10
  • 43
  • 70
ScruffyFox
  • 150
  • 2
  • 9
1

In onCreate()

setContentView(activity_login.xml)

This link is a good starting point if you haven't already been there. It describes the Android lifecylce and has links to other Android resources when getting started

Oleksandr Karaberov
  • 12,573
  • 10
  • 43
  • 70
codeMagic
  • 44,549
  • 13
  • 77
  • 93