Saturday, October 31, 2020

How to display an image saved as “/storage/emulated/0/Download/IMG_1582623402006.jpg” Android studio

Tags

 //Menampilkan gambar dari storage internal

String nm_gb="/storage/emulated/0/Download/IMG_1582623402006.jpg";
if(nm_gb.length()>10) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
options.inSampleSize = 5;
Bitmap scaledBitmap = BitmapFactory.decodeFile(nm_gb, options);
ImageView myGambar=(ImageView)row.findViewById(R.id.icon);
myGambar.setImageBitmap(scaledBitmap);
}else{
ImageView myGambar=(ImageView)row.findViewById(R.id.icon);
myGambar.setImageResource(R.drawable.noimage);

}

Monday, October 5, 2020

Membuat Refres layout Menggunakan SwipeRefreshLayout di Android

Tags

 



Import Gradle support.v4

implementation 'com.android.support:support-v4:28.0.0'

Layout

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">



<Button
android:text="Cari"
android:id="@+id/btncari"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:textColor="#fff"
android:background="@drawable/bg_ui"
android:layout_height="wrap_content">
</Button>


<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/txtcari"
android:layout_toLeftOf="@+id/btncari">
</EditText>

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/btncari">


<ListView
android:layout_height="wrap_content"
android:layout_below="@+id/txtcari"
android:layout_width="wrap_content"
android:id="@android:id/list">
</ListView>

</android.support.v4.widget.SwipeRefreshLayout>


</RelativeLayout>


Deklarasi di .Java

Deklarasi di public ya untuk swipelayoutnya
SwipeRefreshLayout swLayout;


swLayout= (SwipeRefreshLayout) findViewById(R.id.refresh);

swLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swLayout.setRefreshing(false);

new load().execute();//Load Data
}
}, 5000);
}
});

Selamat mencoba,

untuk load data bebas sesuikan data yang akan di muat.