В моей основной деятельности я пытаюсь получить доступ к LinearLayout, который у меня есть в моем основном ScrollView. Мой ScrollView реализуется следующим образом:Android: findViewById возвращает null?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/graph"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="250dip"
/>
</ScrollView>
В моей главной деятельности я вздуть Scrollview, а затем попытаться получить доступ к линейной компоновки следующим образом:
LayoutInflater inflater;
inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ScrollView mainLayout = (ScrollView) inflater.inflate(R.layout.scrollview,
null);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
Почему мой findViewById будет возвращаться нуль здесь? Сначала я подумал, что он пытался найти его, прежде чем он закончил надувание, но я пробовал иметь цикл while, чтобы дождаться, когда он закончит раздувание, и это тоже не поможет.
спасибо! – TrolliOlli