i have class name Main1 that get array of image links & array of text from the main class and display them on listview
. i get error "only the original thread that created a view hierarchy can touch its views" so i search for the solution i found that i use runOnUithread
but it can use only on the oncreate
so i don't know that is the solution. the is is get from the main1 class
the main1 class is
public class Main1 extends ArrayAdapter<String> {
private final Activity context;
private final String[] Cat_Name;
private final String[] logo;
public Main1(Activity context,String[] Cat_Name, String[] logo) {
super(context, R.layout.main1, Cat_Name);
this.context = context;
this.Cat_Name = Cat_Name;
this.logo = logo;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.main1, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.textView1);
final ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView1);
txtTitle.setText(Cat_Name[position]);
Thread thread = new Thread() {
@Override
public void run() {
try {
String img_url=logo[position]; //url of the image
// System.out.println(img_url);
URL url = new URL(img_url);
final Bitmap bmp;
bmp=BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
thread.start();
return rowView;
}
}