android: picture successfully loaded from gallery but dissapears after application restart - android

so if the title sounds confusig, this is what actually happens. In the Activity I have a ImageView and it has a defalut picture. This defalut picture should be shown as long as the user picks another picture from gallery. When he does that, the picture which he picked should be shown as long as he doesn't delete it or picks another one. If he deletes it, the default picture should be shown again until he picks new picture from the gallery.
I have successfuly loaded the picture from the gallery but it stays in the imageview only until the applications restarts. After which the default picture will be shown again. Is there any way to fix this?
This is my code
package com.pumperlgsund.activities;
imports...
public class MainActivity extends FragmentActivity implements
OnHeadlineSelectedListener, View.OnClickListener {
private static int LOAD_IMAGE = 1;
private String selectedImagePath;
private ImageView imgUser;
private TextView txtName;
private TextView txtScore;
private TextView txtValue;
private UserDataController controller;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/ComicNeueSansID.ttf");
controller = new UserDataController(this);
imgUser = (ImageView) findViewById(R.id.imgUser);
imgUser.setOnClickListener(this);
txtName = (TextView) findViewById(R.id.txtUserName);
txtName.setTypeface(tf);
txtName.setText(controller.getUserName());
txtScore = (TextView) findViewById(R.id.txtScore);
txtScore.setTypeface(tf);
txtValue = (TextView) findViewById(R.id.txtValue);
txtValue.setTypeface(tf);
txtValue.setText("" + controller.getScore());
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.imgUser:
onImageClicked(v);
break;
default:
break;
}
}
private void onImageClicked(View view) {
showPopupMenu(view);
}
private void showPopupMenu(View view) {
PopupMenu popupMenu = new PopupMenu(this, view);
popupMenu.getMenuInflater().inflate(R.menu.popupmenu,
popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.item1) {
//TODO: ...
return true;
} else if (item.getItemId() == R.id.item2) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Load Image"), LOAD_IMAGE);
return true;
} else {
return false;
}
}
});
popupMenu.show();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == LOAD_IMAGE) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imgUser.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
layout
ImageView has id imgUser, located in RelativLayout user_area_content
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_frame"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/backgroundColor"
android:orientation="horizontal"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<LinearLayout
android:id="#+id/static_area"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/user_area"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/user_area_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:id="#+id/imgUser"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_marginLeft="8dip"
android:layout_marginTop="8dip"
android:src="#drawable/ic_img_user" />
<TextView
android:id="#+id/txtUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dip"
android:layout_marginTop="8dip"
android:layout_toRightOf="#id/imgUser"
android:text="#string/placeholder"
android:textColor="#color/blue"
android:textSize="16sp" />
<TextView
android:id="#+id/txtScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtUserName"
android:layout_marginLeft="8dip"
android:layout_marginTop="8dip"
android:layout_toRightOf="#id/imgUser"
android:text="#string/score"
android:textColor="#color/blue"
android:textSize="16sp" />
<TextView
android:id="#+id/txtValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtUserName"
android:layout_marginLeft="8dip"
android:layout_marginTop="8dip"
android:layout_toRightOf="#id/txtScore"
android:text="#string/placeholder"
android:textColor="#color/blue"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
<fragment
android:id="#+id/headlines_fragment"
android:name="com.pumperlgsund.fragments.HeadlinesFragment"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_marginTop="16dip"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="#+id/dynamic_frame"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="16dip"
android:layout_weight="2"
android:orientation="horizontal" />
Thx for help!

The default image is 'shown again' every time the view are (re)built i.e. every time the Activity is created, when the application is started, but also on device rotation. You should save the path to the selected image (in onActivityResult()) and retrieve it in onCreate(). The simplest way to save the path is probably to use a SharedPreferences.
If you want to restrict the selection to local images, add the EXTRA_LOCAL_ONLY extra to the intent.

Related

How to load multiple images on the same imageview by clicking a button?

Basically, I want to have an AlertDialog in which multiple images will load on the same ImageView. By clicking the NEXT button it will get the next image bitmap from bitmap list and finally will load on that ImageView. Same case for PREV button. It will take previous bitmap and will load the image on the same ImageView.
But the problem is after loading the first image it does not load the next image. If I click the next button then it takes the next bitmap but the imageview.setImageBitmap(bitmap) does not work.
How to remove or clear the previous image to place the next photos?
The XML file are given below :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/question"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:text="#string/question"
android:textSize="14sp"
android:textColor="#color/light_black"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/divider"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/selected_place_images"
android:scaleType="centerCrop"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/divider"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="47dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/previous"
android:text="#string/previous_page"
android:textColor="#color/black"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:text="#string/next_page"
android:textColor="#color/black"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
The java code are given below :
private void showDialogOfImages() {
Log.d(TAG,"showDialogOfImages : showing places images");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = this.getLayoutInflater();
View customLayout = inflater.inflate(R.layout.custom_displaying_selected_place_images,null);
mSelectedPlaceImages = (ImageView) customLayout.findViewById(R.id.selected_place_images);
nextPage = (TextView) customLayout.findViewById(R.id.next);
previousPage = (TextView) customLayout.findViewById(R.id.previous);
displayPhoto();
nextPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentPhotoIndex++;
displayPhoto();
}
});
previousPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentPhotoIndex--;
displayPhoto();
}
});
builder.setView(customLayout);
builder.show();
}
private void displayPhoto() {
if (mCurrentPhotoIndex < mSelectedLocationPhotosBitmap.size()) {
Bitmap bitmap = mSelectedLocationPhotosBitmap.get(mCurrentPhotoIndex);
Toast.makeText(context,""+mCurrentPhotoIndex+" : "+bitmap,Toast.LENGTH_LONG).show();
mSelectedPlaceImages.setImageBitmap(bitmap);
setButtonVisibility();
}
}
private void setButtonVisibility() {
if(mCurrentPhotoIndex == 0 && mSelectedLocationPhotosBitmap.size() == 1){
nextPage.setEnabled(false);
nextPage.setClickable(false);
nextPage.setTextColor(getResources().getColor(R.color.divider));
previousPage.setEnabled(false);
previousPage.setClickable(false);
previousPage.setTextColor(getResources().getColor(R.color.divider));
}
else if (mCurrentPhotoIndex == 0 && mSelectedLocationPhotosBitmap.size() > 1){
nextPage.setEnabled(true);
nextPage.setClickable(true);
nextPage.setTextColor(getResources().getColor(R.color.black));
previousPage.setEnabled(false);
previousPage.setClickable(false);
previousPage.setTextColor(getResources().getColor(R.color.divider));
}
else if (mCurrentPhotoIndex == mSelectedLocationPhotosBitmap.size()-1 && mSelectedLocationPhotosBitmap.size() > 1){
nextPage.setEnabled(false);
nextPage.setClickable(false);
nextPage.setTextColor(getResources().getColor(R.color.divider));
previousPage.setEnabled(true);
previousPage.setClickable(true);
previousPage.setTextColor(getResources().getColor(R.color.black));
}
else{
nextPage.setEnabled(true);
nextPage.setClickable(true);
nextPage.setTextColor(getResources().getColor(R.color.black));
previousPage.setEnabled(true);
previousPage.setClickable(true);
previousPage.setTextColor(getResources().getColor(R.color.black));
}
}
You need to clear the previous image from imageview and then you can set the new on top.
Do as below
private void displayPhoto() {
if (mCurrentPhotoIndex < mSelectedLocationPhotosBitmap.size()) {
Bitmap bitmap = mSelectedLocationPhotosBitmap.get(mCurrentPhotoIndex);
Toast.makeText(context,""+mCurrentPhotoIndex+" : "+bitmap,Toast.LENGTH_LONG).show();
mSelectedPlaceImages.setImageBitmap(null)
mSelectedPlaceImages.setImageBitmap(bitmap);
setButtonVisibility();
}
}
Try this:
mSelectedPlaceImages.destroyDrawingCache();
mSelectedPlaceImages.setImageBitmap(bitmap);
mSelectedPlaceImages.buildDrawingCache();

Dialog Box to select an image from gallery

I am trying to show a dialog box where ever an ImageButton is pressed, and then choose either pictures from gallery or take some from camera.
I am already struggling to select an image and insert it into the right image view.
Right now, clicking ImageButton (android:id="#+id/imageSelect") will bring up the dialog box, then select choose from gallery, but it insert the image into (android:id="#+id/imageSelect1) which should be inserted into (android:id="#+id/imageSelect).
And when I select (android:id="#+id/imageSelect1) it just overwrite the image, so (android:id="#+id/imageSelect) remains empty
I have a feeling that something is wrong in the SelectPhotoDialog Class.
Doing with without the Dialog box works fine, but I would like to have that option to choose from camera or gallery.
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Image 1" />
<ImageButton
android:id="#+id/imageSelect"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:background="#android:color/white"
android:scaleType="centerCrop"
/>
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Image 2" />
<ImageButton
android:id="#+id/imageSelect1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:background="#android:color/white"
android:scaleType="centerCrop"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Image 3" />
<ImageButton
android:id="#+id/imageSelect2"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:background="#android:color/white"
android:scaleType="centerCrop"
/>
<EditText
android:id="#+id/input_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Title"
android:inputType="textPersonName"
android:padding="7dp"
android:singleLine="true"
android:textSize="14sp" />
<EditText
android:id="#+id/input_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Description"
android:inputType="textMultiLine"
android:padding="7dp"
android:textSize="14sp" />
<EditText
android:id="#+id/input_price"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Price"
android:inputType="numberDecimal"
android:padding="7dp"
android:textSize="14sp" />
<EditText
android:id="#+id/input_country"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Country"
android:inputType="textCapWords"
android:padding="7dp"
android:textSize="14sp" />
<EditText
android:id="#+id/input_state_province"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="State/Province/Region"
android:inputType="textCapWords"
android:padding="7dp"
android:textSize="14sp" />
<EditText
android:id="#+id/input_city"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="City"
android:inputType="textCapWords"
android:padding="7dp"
android:textSize="14sp" />
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Your Contact Email"
android:inputType="textEmailAddress"
android:padding="7dp"
android:textSize="14sp" />
<Button
android:id="#+id/btn_post"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:background="#color/colorPrimary"
android:text="Post"
android:textColor="#android:color/white" />
<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/progressBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:visibility="invisible"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
My post fragment file:
private void init(){
mSelectImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: opening dialog to choose new photo");
SelectPhotoDialog dialog = new SelectPhotoDialog();
dialog.show(getFragmentManager(), getString(R.string.dialog_select_photo));
dialog.setTargetFragment(PostFragment.this, 1);
}
});
mSelectImage1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: opening dialog to choose new photo");
SelectPhotoDialog dialog1 = new SelectPhotoDialog();
dialog1.show(getFragmentManager(), getString(R.string.dialog_select_photo1));
dialog1.setTargetFragment(PostFragment.this, 2);
}
});
SelectPhotoDialog file:
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_selectphoto, container, false);
TextView selectPhoto = (TextView) view.findViewById(R.id.dialogChoosePhoto);
selectPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: accessing phones memory.");
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
}
});
TextView selectPhoto1 = (TextView) view.findViewById(R.id.dialogChoosePhoto1);
selectPhoto1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: accessing phones memory.");
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICKFILE_REQUEST_CODE1);
}
});
TextView takePhoto = (TextView) view.findViewById(R.id.dialogOpenCamera);
takePhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: starting camera.");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
});
return view;
}
Complete PostFragment file:
https://pastebin.com/PJXB3cq1
Complete SelectPhotoDialog
https://pastebin.com/fF2Jj986
IniversalImageLoader file
Universal image loader
I'm not sure, but i don't think there is enough information... i can't find the UniversalImageLoader that is referenced, i imagine that it handles the actual setting of the image, as setImage implies.
   
#Override
    public void getImagePath(Uri imagePath) {
        Log.d(TAG, "getImagePath: setting the image to imageview");
       // THIS LINE UniversalImageLoader.setImage(imagePath.toString(), mSelectImage);
 
        //assign to global variable
        mSelectedBitmap = null;
        mSelectedUri = imagePath;
    }
Update to Answer
OK, So here's how i usually perform the dialog you are using
private static final int READ_REQUEST_CODE = 42;
public void performFileSearch()
{
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Filter to show only images, using the image MIME data type.
// If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
// To search for all documents available via installed storage providers,
// it would be "*/*".
intent.setType("*/*");
startActivityForResult(intent, READ_REQUEST_CODE);
}
#Override
public void onActivityResult(int requestCode, int resultCode,
Intent resultData)
{
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK)
{
Uri uri = null;
if (resultData != null)
{
uri = resultData.getData();
String back = uri.toString();
// DO SOMETHING WITH STRING
}
}
}
SO THEN YOUR CODE WOULD BE
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_selectphoto, container, false);
TextView selectPhoto = (TextView) view.findViewById(R.id.dialogChoosePhoto);
selectPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: accessing phones memory.");
performFileSearch()
}
});
TextView selectPhoto1 = (TextView) view.findViewById(R.id.dialogChoosePhoto1);
selectPhoto1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: accessing phones memory.");
performFileSearch();
}
});
TextView takePhoto = (TextView) view.findViewById(R.id.dialogOpenCamera);
takePhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: starting camera.");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
});
return view;
}
// I don't think that this is the cause, just because everything seems to flow through until the part that set's the image... The dialog will return a uri to the image, but another code is setting the image in the wrong place,
ImageView X = (ImageView) findViewById(R.id.ImageViewID);
X.setBackgroundResource ?
Or something similar, is what im looking for, i think it may be causing the problem.
Scratch that
I found the ImageLoader, and everything seems ok ..
Constructor Detail:
ImageLoader
public ImageLoader(RequestQueue queue, ImageLoader.ImageCache imageCache)Constructs a new ImageLoader.
// Parameters:queue - The RequestQueue to use for making image requests.imageCache - The cache to use as an L1 cache.
Have you tried another form of setting the image ?

Uploading multiple images as clickable ImageViews from table layout

I am new to programming and android. I'm building an app that allows users to upload multiple images by clicking on ImageViews that are displayed in a TableLayout. The problem i am having is how to set the bitmap of each selected image in the onStartActivity method.
I can set a single image to an imageiew by using setImageBitmap but I am unsure how to loop through or programmatically determine which ImageView has been selected in onStartActivity in order to display the image in it. I have created an ImageView array and assigned the ImageViews to it but my attempts to use the array does not display any images. I have also tried to display the ImageView through the setImageBitmap method in each onclicklistener after startActivityForResult - it only displays after the ImageView is selected again, as expected.
How can i make this work? This is my first post. Here is my code:
The XML layout below.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="vertical">
<TextView
android:id="#+id/postAdCommand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:text="Post An Ad"
android:textColor="#ffffff" />
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title:"
android:textColor="#ffffff" />
<EditText
android:id="#+id/etTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description:"
android:textColor="#ffffff" />
<EditText
android:id="#+id/etDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tvImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:text="Upload Images:"
android:textColor="#ffffff" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TableRow>
<ImageView
android:id="#+id/imgImages"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:clickable="true"
android:src="#drawable/add_image" />
<ImageView
android:id="#+id/imgImages1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
<ImageView
android:id="#+id/imgImages2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgImages3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
<ImageView
android:id="#+id/imgImages4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
<ImageView
android:id="#+id/imgImages5"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgImages6"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
<ImageView
android:id="#+id/imgImages7"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
<ImageView
android:id="#+id/imgImages8"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#1f1f14" />
</TableRow>
<Button
android:id="#+id/bImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Upload Images"
android:textColor="#000000" />
</TableLayout>
<TextView
android:id="#+id/tvVideos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Upload Images:"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<VideoView
android:id="#+id/vidVideo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#drawable/back_button_gray"
android:clickable="true" />
<VideoView
android:id="#+id/vidVideo1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#drawable/back_button_gray"
android:clickable="true" />
<VideoView
android:id="#+id/vidVideo2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="2dp"
android:background="#drawable/back_button_gray"
android:clickable="true" />
</LinearLayout>
<Button
android:id="#+id/bVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Upload Video"
android:textColor="#000000" />
<TextView
android:id="#+id/tvPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price:"
android:textColor="#ffffff" />
<EditText
android:id="#+id/etPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/bPostAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Post Your Advertisement" />
</LinearLayout>
</ScrollView>
Then the Java code.
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class PostAd extends AppCompatActivity implements View.OnClickListener {
Button imageUpload;
Button vidUpload;
Button postAd;
ImageView img1, img2, img3, img4, img5, img6, img7, img8, img9;
public static final int SELECT_IMAGE = 1;
private Uri selectedImagePath;
public String selectedFileManager;
public String selectedFilePath;
Bitmap bitmap;
public ImageView[] position = {img1, img2, img3, img4, img5, img6, img7, img8, img9};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post_ad);
initializeVariables();
initOnclickListeners();
}
private void initializeVariables() {
imageUpload = (Button) findViewById(R.id.bImages);
vidUpload = (Button) findViewById(R.id.bVideo);
postAd = (Button) findViewById(R.id.bPostAd);
img1 = (ImageView) findViewById(R.id.imgImages);
img2 = (ImageView) findViewById(R.id.imgImages1);
img3 = (ImageView) findViewById(R.id.imgImages2);
img4 = (ImageView) findViewById(R.id.imgImages3);
img5 = (ImageView) findViewById(R.id.imgImages4);
img6 = (ImageView) findViewById(R.id.imgImages5);
img7 = (ImageView) findViewById(R.id.imgImages6);
img8 = (ImageView) findViewById(R.id.imgImages7);
img9 = (ImageView) findViewById(R.id.imgImages8);
}
private void initOnclickListeners() {
imageUpload.setOnClickListener(this);
vidUpload.setOnClickListener(this);
postAd.setOnClickListener(this);
img1.setOnClickListener(this);
img2.setOnClickListener(this);
img3.setOnClickListener(this);
img4.setOnClickListener(this);
img5.setOnClickListener(this);
img6.setOnClickListener(this);
img7.setOnClickListener(this);
img8.setOnClickListener(this);
img9.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bImages:
break;
case R.id.bVideo:
break;
case R.id.bPostAd:
break;
case R.id.imgImages:
Intent image = new Intent();
image.setType("image/*");
image.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image, SELECT_IMAGE);
break;
case R.id.imgImages1:
Intent image1 = new Intent();
image1.setType("image/*");
image1.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image1, SELECT_IMAGE);
break;
case R.id.imgImages2:
Intent image2 = new Intent();
image2.setType("image/*");
image2.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image2, SELECT_IMAGE);
break;
case R.id.imgImages3:
Intent image3 = new Intent();
image3.setType("image/*");
image3.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image3, SELECT_IMAGE);
break;
case R.id.imgImages4:
Intent image4 = new Intent();
image4.setType("image/*");
image4.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image4, SELECT_IMAGE);
break;
case R.id.imgImages5:
Intent image5 = new Intent();
image5.setType("image/*");
image5.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image5, SELECT_IMAGE);
break;
case R.id.imgImages6:
Intent image6 = new Intent();
image6.setType("image/*");
image6.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image6, SELECT_IMAGE);
break;
case R.id.imgImages7:
Intent image7 = new Intent();
image7.setType("image/*");
image7.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image7, SELECT_IMAGE);
break;
case R.id.imgImages8:
Intent image8 = new Intent();
image8.setType("image/*");
image8.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(image8, SELECT_IMAGE);
break;
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_IMAGE && resultCode == RESULT_OK) {
try {
selectedImagePath = data.getData();
selectedFileManager = selectedImagePath.getPath();
selectedFilePath = getPath(selectedImagePath);
bitmap = BitmapFactory.decodeFile(selectedFilePath);
if (position.length == 0) {
position[0].setImageBitmap(bitmap);
} else if (position.length == 1) {
position[1].setImageBitmap(bitmap);
} else if (position.length == 2) {
position[2].setImageBitmap(bitmap);
} else if (position.length == 3) {
position[3].setImageBitmap(bitmap);
} else if (position.length == 4) {
position[4].setImageBitmap(bitmap);
} else if (position.length == 5) {
position[5].setImageBitmap(bitmap);
} else if (position.length == 6) {
position[6].setImageBitmap(bitmap);
} else if (position.length == 7) {
position[7].setImageBitmap(bitmap);
} else if (position.length == 8) {
position[8].setImageBitmap(bitmap);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
private String getPath(Uri uri) {
String[] projection = {MediaStore.Images.Media.DATA};
Cursor c = getContentResolver().query(uri, projection, null, null, null, null);
if (c != null) {
int column_index = c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
c.moveToFirst();
return c.getString(column_index);
} else return null;
}
}
In your case you need to keep track of each of imageview with position rather than using array
imageView.setTag(position)
imageView.getTag(position)
based on it you can set your logic .

Android there is some way for don't waste layout when orientation change?

I have an application that have a TableLayout with 60 texviews.
The user can touch them and a DialogActivity start for take the text and background color of the clicked TextView.
But the app have a bug that some times all TextView take the color of the first inputed color and inside of the code i haven't a loop that assign the color.
I think that, the problem come from to the orientation of the screen (possible?).
Because the Activity that contain TableLayout is landscape and the Dialog is portrait.
Infact when the Dialog start behind it there is the Activity that change his orientation with the Dialog and all textviews change their color.
How can i avoid this bug?
Why this happend?
Acitivity landscape:
public class ActivitySetOrario extends ActionBarActivity {
//Static perch� cosi non perdo i dati inseriti in precedenza!
static int clickedTextViewId; // Declare TextView as class level member field
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_orario);
MySQLiteHelper db = new MySQLiteHelper(this);
//Get all materie inside database
List<Materia> materia = db.getAllMaterie();
//change all TextView inputed from user
if(materia.isEmpty()){
//do nothing
}else {
for (Materia mat : materia) {
//Change all the TextView with values stored inside the database
TextView changedtextview = (TextView) findViewById(mat.getID());
changedtextview.setText(mat.getMateria());
changedtextview.setBackgroundColor(mat.getColor());
}
}
}//Fine oncreate
//Prende indietro la materia aggiunta dall'ActivityAddMateria
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 1) {
if (resultCode == RESULT_OK) {
MySQLiteHelper db = new MySQLiteHelper(this);
String result = data.getStringExtra("result"); //Take the materia from Dialog
int color = data.getIntExtra("color", 1); //Take the color from Dialog
//Here i need to recognize row and column
db.addMateria(new Materia(clickedTextViewId, result, color));
TextView clickedtextView = (TextView) findViewById(clickedTextViewId); //(TextView) view;
clickedtextView.setText(result);
clickedtextView.setBackgroundColor(color);
}
if (resultCode == RESULT_CANCELED) {
//Nessuna materia inserita
}
}
}//onActivityResult
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_set_orario, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case R.id.draw_orario:
//addMateria();
MySQLiteHelper db = new MySQLiteHelper(this);
db.deleteMateria();
onStart();
return true;
case R.id.save_data_orario:
//SERIALIZZO I DATI CHE DOVRA PRENDERE ActivityOrario
backToOrario();
finish();
return true;
case R.id.exit_orario:
//Torno alla schermata orario annullo ogni modifica NON SERIALIZZO
backToOrario();
finish();
return true;
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//Torna alla ActivityOrario
public void backToOrario(){
Intent myIntent = new Intent(ActivitySetOrario.this, ActivityOrario.class);
startActivity(myIntent);
}
public void addMateria(View v){
//To get ID of your TextView do this
clickedTextViewId = v.getId();
//StartActivityForResult perche mi aspetto la materia inserita dall'altra activity
Intent myIntent = new Intent(ActivitySetOrario.this, ActivityAddMateria.class);
ActivitySetOrario.this.startActivityForResult(myIntent, 1);
}
}
The Dialog portrait Activity:
public class ActivityAddMateria extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_materia);
final Button exit_button = (Button) findViewById(R.id.exit_dialog_materia);
exit_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//No input
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
//Exit from Dialog
finish();
}
});
final Button accept_button = (Button) findViewById(R.id.add_materia);
accept_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Find EditText for take data
EditText nome_materia = (EditText)findViewById(R.id.nome_materia);
//Put result into variable result that is send back
String result = nome_materia.getText().toString();
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.group1);
int radioButtonID = radioGroup.getCheckedRadioButtonId();
View radioButton = radioGroup.findViewById(radioButtonID);
Drawable background = radioButton.getBackground();
if (background instanceof ColorDrawable) {
int color = ((ColorDrawable) background).getColor();
Intent returnIntent = new Intent();
returnIntent.putExtra("result",result).putExtra("color",color);
setResult(RESULT_OK,returnIntent);
}
// Exit to Dialog
finish();
}
});
}
}
The xml of the first activity:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_orario"
android:id="#+id/table">
<TableRow
android:id="#+id/dayrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="35dp" >
<TextView
android:id="#+id/d1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lun."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Mar."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Mer."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Gio."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ven."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/d6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sab."
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<ScrollView
android:id="#+id/scrollorario"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/prima_riga"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/h1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textColor="#color/text_orario"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mat11"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text=""/>
<TextView
android:id="#+id/mat12"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat13"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat14"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat15"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
<TextView
android:id="#+id/mat16"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:gravity="center"
android:clickable="true"
android:onClick="addMateria"
android:background="#color/grigio_chiaro"
android:text="" />
</TableRow>
<!--TOO LONG THE XML I CUT IT THE OTHER ROW ARE THE SAME-->
</LinearLayout>
</ScrollView>
</TableLayout>
Some screenshoot:
You shouldn't be using the ids of the textviews in your database: they can change between different compilations of your app. Which could be the culprit. However, the only way they're all being set is in the for loop: you should verify your database is correct and verify that loop is not running every time.

onClick setVisibility visible and GONE doesn't work

I have made a small program in which i have used one button and a WebView. WebView visibility is set GONE
and when i press the button 1st time i want to set visibility to visible and when i press the button 2nd time i want the visibility to be GONE. It should do the same thing consecutively. I have tried to make it work using if ..else and with switch .Its strange that if you click the button a lot of times (depending , it can be 3 or 7 or 9 or even more times) the code start to work.
Please help me.
Here is my code:
public class MyMenu extends Activity {
Button info;
WebView webView;
int see=0 ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_menu);
info = (Button) findViewById(R.id.info);
webView = (WebView) findViewById(R.id.webView1);
webView.setVisibility(View.GONE);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("file:///android_asset/odigies.html");
// make listener for odigies button
info.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (see == 0) {
webView.setVisibility(View.VISIBLE);
see = 1;
} else {
webView.setVisibility(View.GONE);
see = 0;
}
}
});
}
//send app with sms
public void send(View v){
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "Δωρεάν καλή εφαρμογή για Λοττο,τζοκερ,κινο και προτο.https://play.google.com/store/apps/details?id=o.tzogadoros");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
}
//send app with email
public void email(View v){
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.fromParts("mailto",
"", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Εφαρμογή Lotto Android");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Δωρεάν καλή εφαρμογή για Λοττο,τζοκερ,κινο και προτο.Δίνει τυχαίους αριθμούς για τα τυχαιρά παιχνίδια. ");
if (emailIntent.resolveActivity(getPackageManager()) == null) {
Toast.makeText(getApplicationContext(),
"Παρακαλώ παραμετροποίησε τον λογοριασμό email σου", Toast.LENGTH_LONG)
.show();
} else {
// Secondly, use a chooser will gracefully handle 0,1,2+ matching
// activities
startActivity(Intent.createChooser(emailIntent,
"Διάλεξε το email σου"));
}
}
// go to tzoker activity
public void tzoker(final View view) {
startActivity(new Intent(this, Tzoker.class));
}
// go to kino activity
public void kino(final View view) {
startActivity(new Intent(this, Kino.class));
}
// go to lotto activity
public void lotto(final View view) {
startActivity(new Intent(this, MainActivity.class));
}
// go to proto activity
public void proto(final View view) {
startActivity(new Intent(this, Proto.class));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_menu, menu);
return true;
}
}
and the xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaf39b"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MyMenu" >
<ScrollView
android:id="#+id/vertical_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<HorizontalScrollView
android:id="#+id/horizontal_scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eaf39b"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eaf39b"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="lotto"
android:src="#drawable/lottoicon" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="tzoker"
android:src="#drawable/tzokericon" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="kino"
android:src="#drawable/kinoicon" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="proto"
android:src="#drawable/protoicon" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/menuicon" />
</LinearLayout>
<Button
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="#string/Menuodigies"
android:textSize="22sp"
android:textStyle="bold" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/sendsms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="send"
android:text="#string/sms"
android:textSize="22sp"
android:textStyle="bold" />
<Button
android:id="#+id/sendemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="email"
android:text="#string/email"
android:textSize="22sp"
android:textStyle="bold" />
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
Finally when the webview appear there is no zoom controls,why?
Thanks for your time.
Is it better with that ?
#Override
public void onClick(View v) {
if (webView.getVisibility==View.GONE) {
webView.setVisibility(View.VISIBLE);
} else {
webView.setVisibility(View.GONE);
}
}

Categories

Resources