For Downloading the new lesson you have to finish a survey. Then We will Send you The Post :
If you are Now in a Desktop Computer Go to the link below :
<ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.28" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.39" app:srcCompat="@mipmap/ic_launcher" />
public Drawable loadDrawableFromAssets(Context context, String path) { InputStream stream = null; try { stream = context.getAssets().open(path); return Drawable.createFromStream(stream, null); } catch (Exception ignored) {} finally { try { if(stream != null) { stream.close(); } } catch (Exception ignored) {} } return null; }
android.widget.ImageView imageView2 = findViewById(R.id.imageView2); imageView2.setImageDrawable(loadDrawableFromAssets(getApplicationContext(),"image24.jpg"));
নিচের মত হবে :
imageView2.setImageDrawable(loadDrawableFromAssets(getApplicationContext(),"image24.jpg"));
public Bitmap loadBitmapFromAssets(Context context, String path) { InputStream stream = null; try { stream = context.getAssets().open(path); return BitmapFactory.decodeStream(stream); } catch (Exception ignored) {} finally { try { if(stream != null) { stream.close(); } } catch (Exception ignored) {} } return null; }
android.widget.ImageView imageView3 = findViewById(R.id.imageView3); imageView3.setImageBitmap(loadBitmapFromAssets(getApplicationContext(),"image25.jpg"));
<ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:src="@drawable/ic_launcher_background" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.03" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.018" /> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.844" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.056" app:srcCompat="@mipmap/ic_launcher" /> <ImageView android:id="@+id/imageView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.352" app:srcCompat="@mipmap/ic_launcher_round" />
public Drawable loadDrawableFromAssets(Context context, String path) { InputStream stream = null; try { stream = context.getAssets().open(path); return Drawable.createFromStream(stream, null); } catch (Exception ignored) {} finally { try { if(stream != null) { stream.close(); } } catch (Exception ignored) {} } return null; } public Bitmap loadBitmapFromAssets(Context context, String path) { InputStream stream = null; try { stream = context.getAssets().open(path); return BitmapFactory.decodeStream(stream); } catch (Exception ignored) {} finally { try { if(stream != null) { stream.close(); } } catch (Exception ignored) {} } return null; }
//==========================//1//===========================//
android.widget.ImageView imageView = findViewById(R.id.imageView); try { // get input stream InputStream ims = getAssets().open("image28.jpg"); // load image as Drawable Drawable d = Drawable.createFromStream(ims, null); // set image to ImageView imageView.setImageDrawable(d); // imageView2.setImageDrawable(d); //now close the stream: ims .close(); } catch(IOException ex) { return; } //==========================//2//=============================// final android.widget.ImageView imageView2 = findViewById(R.id.imageView2); imageView2.setImageDrawable(loadDrawableFromAssets(getApplicationContext(),"image24.jpg")); //===============================//3//===========================// android.widget.ImageView imageView3 = findViewById(R.id.imageView3); imageView3.setImageBitmap(loadBitmapFromAssets(getApplicationContext(),"image25.jpg"));
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
এবার StartActivity.java ফাইলটি ওপেন করে এই বাটনটিকে ইনিশিয়ালাইজ করে বাটন ক্লিক এর মাধ্যমে যাতে ইমেজ ভিউ নামের এ্যাক্টি ভিটি ওপেন হয় সেই কোড যোগ করব :
মনে করি বাটনটির আইডি হবে বাটন টু, যেটা এক্সএমএল ফাইলে নির্ধারণ করতে হবে :
android:id="@+id/button2"
তাহলে জাভা ফাইলে ইনিশিয়ালাইজ হবে : Button button2 = (Button)findViewById(R.id.button2);
এবার বাটন টু এর জন্য অনক্লিক লিসেনার :
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// বাটন টু ক্লিক করলে যা ঘটবে তা এখানে লিখতে হবে ।
}
});
আমরা লিখলাম যে ইমেজ ভিউ ক্নাস নামে একটি এ্যাক্টিভিটি আছে সেটা ওপেন কর :
Intent i= new Intent(StartActivity.this, ImageView.class);
startActivity(i);
সুতরাং, এখন বাটন টু এর অনক্লিক লিসেনার হবে এরকম :
Button button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent(StartActivity.this, ImageView.class);
startActivity(i);
}
});