2013-11-08 2 views
1

У меня есть проблема найти линейное расположение ... Это XML Layout:андроида findViewById возвращает нуль

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:binding="http://www.gueei.com/android-binding/" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    tools:context=".controllers.ElencoInfrazioni" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="15dp" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="Infrazione: " /> 

     <Spinner 
      android:id="@+id/elencoInfrazioni" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <TableLayout 
     android:id="@+id/tabellaDatiElencoInfrazioni" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="10dp" 
     android:stretchColumns="*" 
     android:visibility="gone" > 

     <TableRow> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Art. 3: " /> 

      <TextView 
       android:id="@+id/articolo3ElencoInfrazioni" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="non specificato" 
       android:textStyle="bold" /> 

      <LinearLayout 
       android:id="@+id/panelArticolo4ElencoInfrazioni" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Art. 4: " /> 

       <TextView 
        android:id="@+id/articolo4ElencoInfrazioni" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="non specificato" 
        android:textStyle="bold" /> 
      </LinearLayout> 
     </TableRow> 
     .... 

код, который обрабатывает расположение:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
      this.setContentView(R.layout.elenco_infrazioni); 
    init(); 
} 
private void init() { 
    tabellaDati = (TableLayout) this 
      .findViewById(R.id.tabellaDatiElencoInfrazioni); 
    elencoInfrazioni = (Spinner) this.findViewById(R.id.elencoInfrazioni); 
    panelArticolo4 = (LinearLayout) this. 
      findViewById(R.id.panelArticolo4ElencoInfrazioni); 
    articolo3 = (TextView) this 
      .findViewById(R.id.articolo3ElencoInfrazioni); 
    articolo4 = (TextView) this 
      .findViewById(R.id.articolo4ElencoInfrazioni); 
} 

Каждый findViewById нормально, за исключением LinearLayout panelArticolo4, который дает мне нуль ... Мне нужен линейный макет, чтобы установить его видимость. Что я делаю неправильно?

Заранее спасибо

+0

Если у вас несколько таблиц в таблице ... вы используете один и тот же идентификатор для LinearLayout для разных строк? – fasteque

ответ

-4

Не используйте слово «это», везде, «это» в вашем инициализации метод refere для инициализации, а не вашей деятельности.

+0

что не имеет значения – tyczj

+0

И неверно – codeMagic

+0

Другие полезные советы? – user2075861

0

Вы уверены, что все другие виды в порядке? Они не будут давать никаких ошибок при инициализации, пока вы не попытаетесь их использовать. Может быть, ваше представление не инициализировано onCreate? Если вы используете фрагменты, вы можете попытаться инициализировать свои представления в onCreateView вместо onCreate.

Смежные вопросы