ここでは、レイアウトの可視性を制御します
if (!(imagepath[i].toString().equals("no picture"))) {
try {
aURL = new URL("http://www.orientaldaily.com.my/"
+ imagepath[i]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
layout_image.setVisibility(View.VISIBLE);
imageview.setVisibility(View.VISIBLE);
imageview.setScaleType(ScaleType.CENTER_CROP);
imageview.setImageBitmap(bm);
} catch (IOException e) {
Log.e("DEBUGTAG", "Remote Image Exception", e);
}
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps,
R.layout.main_alllatestnewslist, from, to);
lv.setAdapter(adapter);
ここで初期化します
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_alllatestnews);
lv = (ListView) findViewById(android.R.id.list);
RelativeLayout temp = (RelativeLayout)findViewById(R.id.layout_temp);
LayoutInflater liInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
temp.addView(liInflater.inflate(R.layout.main_alllatestnewslist, null));
ここに main_alllatestnews.xml があります
<LinearLayout
android:id="@+id/layout_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/layout_menu"
android:layout_below="@id/layout_title"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
ここに main_alllatestnewslist.xml があります
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_temp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_news_list" >
<LinearLayout
android:id="@+id/layout_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_marginTop="10px" >
<ImageView
android:id="@+id/image_alllatestnewstitle"
android:layout_width="134px"
android:layout_height="80px"
android:src="@drawable/image_loading_failed_1"
android:visibility="invisible" />
</LinearLayout>
これを実行すると、行で Nullpointerexception が発生しました
temp.addView(liInflater.inflate(R.layout.main_alllatestnewslist, null)); <-- inflater still null...
これを解決するには?