In your main.xml layout file, you'll want something like the followng
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:id="@+id/vfShow"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:layout_height="fill_parent"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
-------------------------------------------------------------------------------------------------------------
In your example_Layout.xml layout file, you'll want something like the followng
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
-------------------------------------------------------------------------------------------------------------------------------
In code image download from the server and display dynamically in view switcher
In your code then where this layout file is referenced, you can initialize your Views as follows...
public class deal extends Activity {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
//http://www.example.com/abc/
String imageUrl="http://www.example.com/abc/";
String[] im={"img1.png","img2.png","img3.png","img4.png","img5.png"};
private ImageView imageLoader;
private ProgressDialog bar;
private final int ONE = 0;
private ImageView img;
private ViewFlipper vf;
private Context mContext;
private final GestureDetector detector = new GestureDetector(
new MyGestureDetector());
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = this;
//new ImageDownload().execute(im[1]);
vf = (ViewFlipper) this.findViewById(R.id.vfShow);
vf.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
});
Bundle extras = getIntent().getExtras();
String a = extras.getString("deal");
for(int i=0;i<4 br="" i=""> {
img = new ImageView(getApplicationContext());
//AsyncImageLoaderv asyncImageLoaderTop = new AsyncImageLoaderv();
// img.setImageBitmap(new DownloadImagesTask().execute(imageUrl + im[i]));
// ImageView ima =(ImageView)findViewById(R.id.imageView1);
//TextView t= (TextView)findViewById(R.id.textView1);
// t.setText("Deals No - " );
Bitmap bitmap = DownloadImage(imageUrl + im[i]);
img.setImageBitmap(bitmap);
vf.addView(img);
}
vf.setDisplayedChild(1);
Toast.makeText(mContext, "Current Deal are = " +a,Toast.LENGTH_LONG).show();
int a1= Integer.parseInt(a);
for(int i=1;i<=a1 ;i++)
{
vf.showNext();
}
}
View addImageView(int resId) {
ImageView iv = new ImageView(this);
iv.setImageResource(resId);
return iv;
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.left_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.left_out));
vf.showNext();
return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.right_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.right_out));
vf.showPrevious();
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
private InputStream OpenHttpConnection(String urlString)
throws IOException
{
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
}
catch (Exception ex)
{
throw new IOException("Error connecting");
}
return in;
}
private Bitmap DownloadImage(String URL)
{
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
public class DownloadImagesTask extends AsyncTask {
@Override
protected Bitmap doInBackground(String... urls) {
return download_Image(urls[0]);
}
@Override
protected void onPostExecute(Bitmap result) {
img.setImageBitmap(result); // how do I pass a reference to mChart here ?
}
private Bitmap download_Image(String url) {
//---------------------------------------------------
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
// Log.e("Hub","Error getting the image from server : " + e.getMessage().toString());
}
return bm;
//---------------------------------------------------
}
}
}
4>
@Override
protected Bitmap doInBackground(String... urls) {
return download_Image(urls[0]);
}
@Override
protected void onPostExecute(Bitmap result) {
img.setImageBitmap(result); // how do I pass a reference to mChart here ?
}
private Bitmap download_Image(String url) {
//---------------------------------------------------
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
// Log.e("Hub","Error getting the image from server : " + e.getMessage().toString());
}
return bm;
//---------------------------------------------------
}
}
}
Hello everyone I want to introduce you guys to a group a private investigators who can help you with information you need in any situation in life and they are ready to follow you step by step until your case is cleared just contact +17078685071 and you will happily ever after
ReplyDeletePremiumhackservices@gmail.com