This app is supposed to display images in which the students can count up what the money is worth in total, and then input the value in a editText text box, which is then compared against a stored value. Unfortunately, when I try to switch activities past a certain point (there are 11 active activities, with three of them displaying images fine), the images start blurring and the coins are hard to distinguish from each other. I do not know whether this is a Java or XML error, however I have pasted the code below. The following is XML code.
<RelativeLayout 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: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=".Ldsm" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<Button
android:id="#+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/submit" />
</LinearLayout>
<TextView
android:id="#+id/userQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout"
android:layout_alignLeft="#+id/userAnswer"
android:layout_marginBottom="30dp"
android:text="#string/how_many_coins_total"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/userAnswer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/userQuestion"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginTop="118dp" >
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/userQuestion"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/linearLayout"
android:src="#drawable/ic_coin4" />
That's just one of the 7 screens that look blurry when they display the images. The following is the Java code for the same activity.
package com.example.ldsm3;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.example.ldsm3.Problem5;
public class Problem4 extends Activity
{
private final int COIN3_SCREEN_ANSWER = 95;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_problem4);
Button submitButton = (Button)findViewById(R.id.submitButton);
submitButton.setOnClickListener(submitButtonListener);
}
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private OnClickListener submitButtonListener = new OnClickListener()
{
public void onClick(View arg0)
{
EditText editText = (EditText)findViewById(R.id.userAnswer);
int userAnswerValue = Integer.parseInt(editText.getText().toString());
// Build the Alert Dialog
android.app.AlertDialog.Builder alert = new AlertDialog.Builder(Problem4.this);
alert.setTitle("Answer");
alert.setCancelable(false);
if(userAnswerValue == COIN3_SCREEN_ANSWER)
{
alert.setMessage("Congratulations!!!");
}
else
{
alert.setMessage("Sorry, that's not right.");
}
alert.setPositiveButton("OK",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int id)
{
Intent nextCoinScreenIntent = new Intent(Problem4.this, Problem5.class);
startActivity(nextCoinScreenIntent);
}
});
alert.show();
}
};
}
And this a screenshot when it is running on a Nexus 10:
Please let me know if any more information is needed.
It seems like it was fetching the icons that were not designed for the particular screen size. You can fix this by going to the workspace and deleting every icon that is any other folder besides the "drawable" one. (With the exception of the ic_launcher icon, as that is the one that allows you to display your app in the Android app menu and will not get blurry.)
Better than your solution would be to make sure the proper resolution file is in every folder. The proper resolution is your desired resolution with the following multipliers, as shown on the Android Design documents:
Related
This is a tricky problem. I imported a friend's project into Eclipse, and it was full of errors. At first there was a 'Jar mismatch!' that was due to an appcompat_v7 library (auto-imported to every single Eclipse project I use due to 22.6 upgrade) and an android.support.app.v4 library conflict. so i deleted the android.support.app.v4 library in the libs folder since i saw the v7 also included a v4. this made the jar mismatch go away. but then on one Activity, the ActionBarActivity as a class extension was not being recognised. i rolled over it and it said i could fix it by importing appcompat_v7 (which was odd since i thought it was already there by default and clearly was causing a conflict). So i clicked on it and imported it, and that error went away.
But now, none of my layout names in my xml (that are sourced in the Activity) are being recognized, even though the names are all correct and the correct code is there. e.g.
mSpnImageSize = (Spinner) findViewById(R.id.spnImageSize);
spnImageSize has the error on it, saying it cannot be resolved to a field. But I know the xml file is fine, and has that field name in it.
Why is this happening? The project worked perfectly in my friend's computer, so I don't see why it is not working on mine. I also checked my SDK packages and they are all imported (both the support libraries and the API # that my project targets, as well as many other APIs).
Ever since I updated Eclipse to 22.6 (terrible update) I can no longer import other people's projects without all these crazy errors. Thanks in advance for your help.
Here is my Activity file and my activity_layout file, just to show they are okay.
package com.laurengariepy.android.gridimagesearch;
import android.R;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Selection;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class FilterActivity extends ActionBarActivity {
protected static final String FILTERS = "FilterPreferences";
private Spinner mSpnImageSize,
mSpnColorFilter,
mSpnImageType;
private EditText mEtSiteFilter;
private Button mBtnSave;
private ArrayAdapter<CharSequence> aImageSizeAdapter,
aColorFilterAdapter,
aImageTypeAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_filter);
setupViews();
restoreFilterPreferences();
setCursor();
}
private void setupViews() {
mSpnImageSize = (Spinner) findViewById(R.id.spnImageSize);
aImageSizeAdapter = ArrayAdapter.createFromResource(this, R.array.image_size_options,
android.R.layout.simple_spinner_item);
aImageSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpnImageSize.setAdapter(aImageSizeAdapter);
mSpnColorFilter = (Spinner) findViewById(R.id.spnColorFilter);
aColorFilterAdapter = ArrayAdapter.createFromResource(this, R.array.color_filter_options,
android.R.layout.simple_spinner_item);
aColorFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpnColorFilter.setAdapter(aColorFilterAdapter);
mSpnImageType = (Spinner) findViewById(R.id.spnImageType);
aImageTypeAdapter = ArrayAdapter.createFromResource(this, R.array.image_type_options,
android.R.layout.simple_spinner_item);
aImageTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpnImageType.setAdapter(aImageTypeAdapter);
mEtSiteFilter = (EditText) findViewById(R.id.etSiteFilter);
mBtnSave = (Button) findViewById(R.id.btnSave);
mBtnSave.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent();
setResult(RESULT_OK, i);
finish();
}
});
}
private void restoreFilterPreferences() {
SharedPreferences filters = getSharedPreferences(FILTERS, 0);
int imageSizeSelection = filters.getInt("image_size", 0);
mSpnImageSize.setSelection(imageSizeSelection);
int colorFilterSelection = filters.getInt("color_filter", 0);
mSpnColorFilter.setSelection(colorFilterSelection);
int imageTypeSelection = filters.getInt("image_type", 0);
mSpnImageType.setSelection(imageTypeSelection);
String siteFilterSelection = filters.getString("site_filter", mEtSiteFilter.getHint().toString());
mEtSiteFilter.setText(siteFilterSelection);
}
private void setCursor() {
int position = mEtSiteFilter.length();
Selection.setSelection(mEtSiteFilter.getText(), position);
}
#Override
protected void onPause() {
super.onPause();
saveFilterPreferences();
}
private void saveFilterPreferences() {
SharedPreferences filters = getSharedPreferences(FILTERS, 0);
SharedPreferences.Editor editor = filters.edit();
editor.putInt("image_size", mSpnImageSize.getSelectedItemPosition());
editor.putInt("color_filter", mSpnColorFilter.getSelectedItemPosition());
editor.putInt("image_type", mSpnImageType.getSelectedItemPosition());
editor.putString("site_filter", mEtSiteFilter.getText().toString());
editor.commit();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.filter, menu);
return true;
}
}
The accompanying xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvFilterHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:textStyle="bold"
android:textSize="22sp"
android:text="#string/tv_filter_header" />
<TextView
android:id="#+id/tvImageSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvFilterHeader"
android:layout_margin="10dp"
android:textSize="18sp"
android:text="#string/tv_image_size" />
<Spinner
android:id="#+id/spnImageSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#+id/tvImageSize"
android:layout_toRightOf="#+id/tvImageSize"
android:textSize="18sp"
android:spinnerMode="dropdown" />
<TextView
android:id="#+id/tvColorFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvImageSize"
android:layout_margin="10dp"
android:textSize="18sp"
android:text="#string/tv_color_filter" />
<Spinner
android:id="#+id/spnColorFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#+id/tvColorFilter"
android:layout_toRightOf="#+id/tvColorFilter"
android:textSize="18sp"
android:spinnerMode="dropdown" />
<TextView
android:id="#+id/tvImageType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvColorFilter"
android:layout_margin="10dp"
android:textSize="18sp"
android:text="#string/tv_image_type" />
<Spinner
android:id="#+id/spnImageType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#+id/tvImageType"
android:layout_toRightOf="#+id/tvImageType"
android:textSize="18sp"
android:spinnerMode="dropdown" />
<TextView
android:id="#+id/tvSiteFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvImageType"
android:layout_margin="10dp"
android:textSize="18sp"
android:text="#string/tv_site_filter" />
<EditText
android:id="#+id/etSiteFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tvSiteFilter"
android:layout_toRightOf="#+id/tvSiteFilter"
android:ems="10"
android:hint="#string/et_filter_hint" >
<requestFocus />
</EditText>
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvSiteFilter"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:text="#string/btn_save" />
</RelativeLayout>
Remove this
import android.R;
You imported R from the android framework.
Instead it should be
import com.laurengariepy.android.gridimagesearch.R;
// your packagename.R
Its been few days over to me, learning Android App development :
I have created an APK which is having two buttons (largeButton & smallButton) if you click on these button test will large and small accordingly.
What i am trying to do :
When i click second time button should change in previous mode i.e Vice Versa should happen.
Here is my code :
mainActivity:
package com.firstapk.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button largButton;
Button smallButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
largButton = (Button) findViewById(R.id.largbutton);
smallButton = (Button) findViewById(R.id.smallbutton);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//public void getDisplay(View view){
public void largebuttonclick(View view){
try{
largButton.setTextSize(40);
}catch(Exception e){
Log.d("TestApp", e.getMessage());
}
}
//}
public void smallButtonClick(View view){
try{
smallButton.setTextSize(5);
}catch(Exception e){
Log.d("TestApp",e.getMessage());
}
}
}
activity_main.xml
<RelativeLayout 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: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=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:id="#+id/largbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="96dp"
android:onClick="largebuttonclick"
android:text="#string/button_large" />
<Button
android:id="#+id/smallbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="320dp"
android:onClick="smallButtonClick"
android:text="#string/button_small" />
</RelativeLayout>
As you did now it's right, if he click "Max size" he will see max size;
So maybe you want to use only one button which works like (+ and -)? If yes use one onClick and a boolean variable to save the current status (max size, small size).
private boolean maxSize; // false if small, true if max
public void onChangeSize(View view)
{
if (maxSize)//max->small
{
smallButton.setTextSize(5);
}
else//small->max
{
largButton.setTextSize(40);
}
maxSize = !maxSize;
}
Then android:onClick="onChangeSize" in the two buttons xml.
You could use the same approch for your current code, but it will work in the same way.
I have created an application where users can send and share text that they have input, if they click the send button, the text that they input will be displayed, if they click the share button, the application opens up a list of sharing methods (GMail, Messaging etc..), what I want is though, to allow the users to view there text and then share it, hwoever, when the user clicks send and it goes to the file activity_display, the text shows, but the button does not. Any ideas why? Could you fix this? Here's the code;
activity_display_message.xml:
<RelativeLayout 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: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=".DisplayMessageActivity" >
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="shareMessage"
android:layout_below="#+id/text_view"
android:text="test" />
</RelativeLayout>
MAIN PROBLEM: Button Share does not show.
EDIT: I suspect I may need to include something to this file, here's the code, any help?
DisplayMessageActivity.java:
package com.example.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
public class DisplayMessageActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
/**
* Set up the {#link android.app.ActionBar}, if the API is available.
*/
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.display_message, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Since you are using RelativeLayout you need to specify where to layout your views. Try this for example:
<RelativeLayout 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: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=".DisplayMessageActivity" >
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="shareMessage"
android:layout_below="#+id/text_view"
android:text="test" />
you are using relative layout. use linear layout instead. this will solve your problem.
You are using a relative layout. The objects are overlapping because you have not set them up to be LeftOf or Below or something like that.
Just replace your button with:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:onClick="shareMessage"
android:text="#string/button_share" />
And TextView with this:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
I surdenly noticed that My project starts throwing error anytime I try to access a resources that is a button. It underlines R.id.button. I dont understand why. I even deleted the last xml that I created but problem persist.
This is an example of my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/layoutborder"
android:orientation="vertical" >
<TextView
android:id="#+id/chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/stepone"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/wine" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:src="#drawable/ai" />
<Button
android:id="#+id/drugdetails"
style="#style/smallButtonStyleBlackpearl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="#string/nextbut" />
</LinearLayout>
My Java code
package com.example.rhemahealthcare;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockActivity;
import com.example.rhemahealthcare.R;
public class SteponeActivity extends SherlockActivity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.steponeactivity);
final Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
// TODO Auto-generated method stub
Intent intent = new Intent(SteponeActivity.this,SteptwoActivity.class);
startActivity(intent);
}
});
}
}
i think you change any button1 id buy clicking right click and choose edit id. this option changes all the ids with that name in all the layouts.
As #Aleks G gussed it right in the comment, you don't have any button with id as button1 in your xml file. You've mentioned it :
final Button button = (Button)findViewById(R.id.button1);
Use the appropriate ID or put one in your layout file.
I have figured out the problem. My button ids were automatically change to button1 so they did not reference their previous ids that I gave to them. Thanks alot
i'm a newbie of android :)
I want to create a simple slideshow with a numeric parameter(x) and a button.I have 21 images and, at the click of the button, I want to catch x and "slide" only the first x images of the list.Between one image and the next i want wait 1 second.
At the end i want to know how much time passed during the operation. (sorry for my english)
paste below the code of the activity and the layout:
package com.superpibenchmarknative;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class ImageActivity extends Activity implements OnClickListener {
private Button start;
private EditText iteractions;
private TextView time;
private ImageView display;
private long after,before;
private int images[] = {R.drawable.image1,R.drawable.image2,R.drawable.image3,
R.drawable.image4,R.drawable.image5,R.drawable.image6,R.drawable.image7,
R.drawable.image8,R.drawable.image9,R.drawable.image10,R.drawable.image11,
R.drawable.image12,R.drawable.image13,R.drawable.image14,R.drawable.image15,
R.drawable.image16,R.drawable.image17,R.drawable.image18,R.drawable.image19,
R.drawable.image20,R.drawable.image21,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
setUpUI();
}
private void setUpUI() {
// TODO Auto-generated method stub
start = (Button) findViewById(R.id.bntStartCalcolation);
iteractions = (EditText) findViewById(R.id.etIterations);
time = (TextView) findViewById(R.id.tvTime);
start.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
//Creo le imageview in base al # di iteractions
before = System.currentTimeMillis();
for (int j = 0; j < Integer.parseInt(iteractions.getText().toString());j++){
display = (ImageView) findViewById(R.id.ivDisplay);
display.setImageResource(images[j]);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
display = null;
System.gc();
}
}, 1000);
}
display = null;
System.gc();
after = System.currentTimeMillis();
time.setText(String.valueOf(after-before-1000* Integer.parseInt(iteractions.getText().toString())));
}
}
and this is the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".ImageActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Benchmark del rendering di immagini" />
<EditText
android:id="#+id/etIterations"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:hint="# di iterazioni"
android:inputType="number"
android:padding="5dp" />
<Button
android:id="#+id/bntStartCalcolation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:text="Start Calcolation" />
<ImageView android:id="#+id/ivDisplay"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight="50"
android:text="Risultato ottenuto in: " />
<TextView
android:id="#+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight="50" />
</LinearLayout>
this code dosn't work, it create an exception
OutOfMemoryError: bitmap size exceed the vm budget
anyone can help me to solve this problem?? :) thanks at all however :D
great all works :D but i've a little more questions
I don't understand why the time is always negative!!!
anyone of you know why?? [postDelayed not works?!? :( ]
solved with: android.os.SystemClock.sleep(1000);
Another error, the ImageView dosn't change after the setting of an image, any suggestions??
There is a small guide within the developer site regarding loading large bitmap files. The idea is to load lower resolution files so that they should fit in memory: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Add the largeheap to your application in your Manifest file.
<application ... android:largeHeap="true" >
Alternatively, make your photos smaller. You might have a variety of sizes dependent on what size of screen you are using, that will make it much less likely to take all of the memory up. See this page to find Android screen resolutions.