public class test extends Activity {
ImageView imView;
ImageView imViewLine;
String imageUrl="http://www.web.com/app/";
String FileType = ".png";
int imageNum = 0;
Random r;
int count = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
r= new Random();
ListView myListView = (ListView)findViewById(R.id.myListView);
final ArrayList<String> todoItems = new ArrayList<String>();
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this,R.layout.line,todoItems);
//Bind the listview to the array adapter
myListView.setAdapter(aa);
for(count = 0; count < 2; count++){
todoItems.add(0, "TEST");
downloadFile(imageUrl + Integer.toString(count) + FileType);
aa.notifyDataSetChanged();
}
}
Bitmap bmImg;
void downloadFile(String fileUrl){
URL myFileUrl =null;
try {
myFileUrl= new URL(fileUrl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
imViewLine.setImageBitmap(bmImg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/icon"
android:layout_width="90px"
android:paddingLeft="2px"
android:paddingRight="2px"
android:paddingTop="2px"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10px"
android:paddingTop="5px"
android:textSize="10sp"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/myImageButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New To Do Item"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
views:
563answers:
1
A:
Hi. Make sure you set appropriate permissions in the application manifest file:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Also, it seems to me that imViewLine
is not instantiated, because imViewLine.setImageBitmap(bmImg);
cause a NullPointerException
.
Hope that helps.
Regards Thomas