I have an imageView with some texts that i want to save into my sdcard by onClick button. This is how i implement it:
ImageView blankcard= (ImageView) findViewById(R.id.blankcard);
blankcard.setBackgroundResource(R.drawable.temp3);
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Display the message in textview
TextView stv1 = (TextView) findViewById(R.id.crdName);
TextView stv2 = (TextView) findViewById(R.id.crdCompany);
TextView stv3 = (TextView) findViewById(R.id.crdPhone);
TextView stv4 = (TextView) findViewById(R.id.crdMobile);
TextView stv5 = (TextView) findViewById(R.id.crdAddress);
TextView stv6 = (TextView) findViewById(R.id.crdWebsite);
TextView stv7 = (TextView) findViewById(R.id.crdEmail);
TextView stv8 = (TextView) findViewById(R.id.crdTitle);
Intent intent=getIntent();
String Name = intent.getStringExtra("name");
String Company = intent.getStringExtra("company");
String Phone = intent.getStringExtra("phone");
String Mobile = intent.getStringExtra("mobile");
String Address = intent.getStringExtra("address");
String Email = intent.getStringExtra("email");
String Website = intent.getStringExtra("website");
String Title = intent.getStringExtra("title");
stv1.setText(Name+" ");
stv2.setText(Company);
stv3.setText(" "+Phone);
stv4.setText(Mobile+" ");
stv5.setText(" "+Address);
stv6.setText(" "+Email);
stv7.setText(Website+" ");
stv8.setText(Title+" ");
stv1.setVisibility(View.VISIBLE);
stv2.setVisibility(View.VISIBLE);
stv3.setVisibility(View.VISIBLE);
stv4.setVisibility(View.VISIBLE);
stv5.setVisibility(View.VISIBLE);
stv6.setVisibility(View.VISIBLE);
stv7.setVisibility(View.VISIBLE);
stv8.setVisibility(View.VISIBLE);
blankcard.setBackgroundResource(R.drawable.temp3);
blankcard.setDrawingCacheEnabled(true);
Bitmap bitmap = blankcard.getDrawingCache();
String root = Environment.getExternalStorageDirectory().toString();
File newDir = new File(root + "/MapCards");
newDir.mkdirs();
Random gen = new Random();
int n = 10000;
n = gen.nextInt(n);
String fotoname = "Photo-"+ n +".jpg";
File file = new File (newDir, fotoname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
Toast.makeText(getApplicationContext(), "Saved to your folder", Toast.LENGTH_SHORT ).show();
} catch (Exception e) {
}
}
});
Once the button is clicked, file is created in certain directory and image view is saved in. But i can only see the template, not the texts i already set on imageView. How can i use Drawable more efficiently to achieve this? Thank you.
EDIT:
.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stainbck"
android:orientation="vertical"
android:padding="25dp" >
<LinearLayout
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="3" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginTop="30dp" >
<ImageView
android:id="@+id/blankcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
<TextView
android:id="@+id/crdCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Company"
android:textColor="#20526d"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/crdWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:text="website"
android:textColor="#20526d"
android:textSize="9sp"
android:textStyle="bold" />
<TextView
android:id="@+id/crdAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/crdPhone"
android:layout_alignParentLeft="true"
android:text="address"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/crdEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/crdWebsite"
android:layout_alignBottom="@+id/crdWebsite"
android:layout_alignParentRight="true"
android:text="email"
android:textColor="#20526d"
android:textSize="9sp"
android:textStyle="bold" />
<TextView
android:id="@+id/crdPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/crdWebsite"
android:layout_alignParentLeft="true"
android:layout_marginBottom="17dp"
android:text="phone"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/crdName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/crdCompany"
android:text="name"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/crdTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/crdName"
android:layout_marginTop="12dp"
android:text="title"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/crdMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/crdTitle"
android:layout_marginTop="5dp"
android:text="mobile"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>