Search Results

Search found 135 results on 6 pages for 'layoutparams'.

Page 6/6 | < Previous Page | 2 3 4 5 6 

  • Android GridView - How to change a bitmap dynamically?

    - by Alborz
    Hello I have a gridView which I use to show some pictures on (small thumb of diffrent levels). When the user finishes one level, I would like to change the thumb for that level. (Somehow show that it has been completed). I created two thumbs for each level. One is the original and one that shows that the level is completed. But how can i change the source of the images? The code which I use to draw the images looks like this. The main activity: /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maps); GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ImageAdapter(this)); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { //Open the map which was clicked on, if there is one if(position+1 > 1){ Toast.makeText(maps.this, "Level " + (position+1) + " is not yet available!", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(maps.this, "Opening Level " + (position+1), Toast.LENGTH_SHORT).show(); Intent myIntent = new Intent(v.getContext(), Tutorial2D.class); startActivity(myIntent); } } }); } The ImageAdapter Class: public class ImageAdapter extends BaseAdapter { private Context mContext; public ImageAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } // create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, initialize some attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(8, 8, 8, 8); } else { imageView = (ImageView) convertView; } //Changing imageView.setImageResource(mThumbIds[position]); return imageView; } // references to our images private Integer[] mThumbIds = { R.drawable.map1, R.drawable.map2, R.drawable.map3, R.drawable.map4, R.drawable.map5, R.drawable.map6, R.drawable.map7, R.drawable.map8, R.drawable.map9, R.drawable.map10, R.drawable.map11, R.drawable.map12, R.drawable.map13, R.drawable.map14, R.drawable.map15, R.drawable.map16, R.drawable.map17, R.drawable.map18, R.drawable.map19 }; }

    Read the article

  • Android - dialer icon gets placed in recently used apps after finish()

    - by Donal Rafferty
    In my application I detect the out going call when a call is dialled from the dialer or contacts. This works fine and I then pop up a dialog saying I have detected the call and then the user presses a button to close the dialog which calls finish() on that activity. It all works fine except that when I then hold the home key to bring up the recently used apps the dialer icon is there. And when it is clicked the dialog is brought back into focus in the foreground when the dialog activity should be dead and gone and not be able to be brought back to the foreground. Here is a picture of what I mean. So two questions arise, why would the dialer icon be getting placed there and why would it be recalling my activity to the foreground? Here is the code for that Activity which has a dialog theme: public class CallDialogActivity extends Activity{ boolean isRecording; AudioManager audio_service; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog); audio_service = (AudioManager) getSystemService(Context.AUDIO_SERVICE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); Bundle b = this.getIntent().getExtras(); String number = b.getString("com.networks.NUMBER"); String name = b.getString("com.networks.NAME"); TextView tv = (TextView) findViewById(R.id.voip) ; tv.setText(name); Intent service = new Intent(CallAudio.CICERO_CALL_SERVICE); startService(service); final Button stop_Call_Button = (Button) findViewById(R.id.widget35); this.setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); stop_Call_Button.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ Intent service = new Intent(CallAudio._CALL_SERVICE); //this is for Android 1.5 (sets speaker going for a few seconds before shutting down) stopService(service); Intent setIntent = new Intent(Intent.ACTION_MAIN); setIntent.addCategory(Intent.CATEGORY_HOME); setIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(setIntent); finish(); isRecording = false; } }); final Button speaker_Button = (Button) findViewById(R.id.widget36); speaker_Button.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ if(true){ audio_service.setSpeakerphoneOn(false); } else{ audio_service.setSpeakerphoneOn(true); } } }); } @Override protected void onResume() { super.onResume(); } @Override protected void onPause() { super.onPause(); } public void onCofigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } } It calls a service that uses AudioRecord to record from the Mic and AudioTrack to play it out the earpiece, nothing in the service to do with the dialler. Has anyone any idea why this might be happening?

    Read the article

  • disable the Home Button and Back Button"

    - by michael
    i want way to disable the Home Button & Back Button when click on checkbox in application , my application on version 4.2.2 i have code but not work when click on checkbox work stop to application public void HardButtonOnClick(View v) { boolean checked1 = ((CheckBox) v).isChecked(); if(checked1) { SQLiteDatabase db; db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setVersion(1); db.setLocale(Locale.getDefault()); db.setLockingEnabled(true); ContentValues values = new ContentValues(); values.put("hardBtn", "YES"); db.update("Setting", values, "id = ?", new String[] { "1" }); Toast.makeText(this, "Hard Button Locked", Toast.LENGTH_LONG).show(); //SharedPreferences pref = getSharedPreferences("pref",0); //SharedPreferences.Editor edit = pref.edit(); //edit.putString("hard","yes"); //edit.commit(); /* String Lock="yes" ; Bundle bundle = new Bundle(); bundle.putString("key", Lock); Intent a = new Intent(Change_setting.this, ChildMode.class); a.putExtras(bundle); startActivity(a);*/ super.onAttachedToWindow(); this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); isLock = true; } else { SQLiteDatabase db; db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setVersion(1); db.setLocale(Locale.getDefault()); db.setLockingEnabled(true); ContentValues values = new ContentValues(); values.put("hardBtn", "NO"); db.update("Setting", values, "id = ?", new String[] { "1" }); //SharedPreferences pref = getSharedPreferences("pref",0); //SharedPreferences.Editor edit = pref.edit(); //edit.putString("hard","no"); //edit.commit(); Toast.makeText(this, "Hard Button Un-Locked", Toast.LENGTH_LONG).show(); isLock = false; } } how can work it??

    Read the article

  • Video Recording Not Working in ICS

    - by Nirav Ranpara
    I have implement code Record video in Android Phone . This code is working in 2.2 , 2.3 . not in ICS But when I checked in ICS code is not working ? here I posted code and xml file. videorecord.java import java.io.File; import java.io.IOException; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.hardware.Camera; import android.media.CamcorderProfile; import android.media.MediaRecorder; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Environment; import android.util.Log; import android.view.Display; import android.view.KeyEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class videorecord extends Activity{ SharedPreferences.Editor pre; String filename; CountDownTimer t; private Camera myCamera; private MyCameraSurfaceView myCameraSurfaceView; private MediaRecorder mediaRecorder; Integer cnt=0; LinearLayout myButton; TextView myButton1; SurfaceHolder surfaceHolder; boolean recording; private TextView txtcount; private ImageView btnplay; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); recording = false; setContentView(R.layout.videorecord); init(); myCamera = getCameraInstance(); if(myCamera == null){ } myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera); FrameLayout myCameraPreview = (FrameLayout)findViewById(R.id.videoview); Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); myCameraSurfaceView.setLayoutParams(new LinearLayout.LayoutParams(width, height-60)); myCameraPreview.addView(myCameraSurfaceView); myButton = (LinearLayout)findViewById(R.id.mybutton); btnplay.setOnClickListener(myButtonOnClickListener); } private void init() { txtcount = (TextView) findViewById(R.id.txtcounter); //myButton1 = (TextView) findViewById(R.id.mybutton1); btnplay = (ImageView)findViewById(R.id.btnplay); t = new CountDownTimer( Long.MAX_VALUE , 1000) { @Override public void onTick(long millisUntilFinished) { cnt++; String time = new Integer(cnt).toString(); long millis = cnt; int seconds = (int) (millis / 60); int minutes = seconds / 60; seconds = seconds % 60; txtcount.setText(String.format("%d:%02d:%02d", minutes, seconds,millis)); } @Override public void onFinish() { } }; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { if(recording) { new AlertDialog.Builder(videorecord.this).setTitle("Do you want to save Video ?") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { filename(); //finish(); } }).setNegativeButton("Cancle", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }).show(); } else { if ((keyCode == KeyEvent.KEYCODE_BACK)) { //Intent homeIntent= new Intent(Intent.ACTION_MAIN); //homeIntent.addCategory(Intent.CATEGORY_HOME); //homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //startActivity(homeIntent); //this.finishActivity(1); finish(); } //moveTaskToBack(true); // finish(); return super.onKeyDown(keyCode, event); } } else { // Toast.makeText(getApplicationContext(), "asd", Toast.LENGTH_LONG).show(); android.os.Process.killProcess(android.os.Process.myPid()) ; } return super.onKeyDown(keyCode, event); } ImageView.OnClickListener myButtonOnClickListener = new ImageView.OnClickListener(){ public void onClick(View v) { if(recording){ Log.e("Record error", "error in recording ."); mediaRecorder.stop(); t.cancel(); filename(); releaseMediaRecorder(); }else{ releaseCamera(); Log.e("Record Stop error", "error in recording ."); // if(!prepareMediaRecorder()){ prepareMediaRecorder(); finish(); } mediaRecorder.start(); recording = true; // myButton1.setText("STOP Recording"); // btnplay.setImageResource(android.R.drawable.ic_media_pause); btnplay.setImageResource(R.drawable.stoprec); t.start(); } }}; private Camera getCameraInstance(){ Camera c = null; try { c = Camera.open(); } catch (Exception e){ } return c; } private void filename() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Save Video"); alert.setMessage("Enter File Name"); final EditText input = new EditText(this); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if(input.getText().length()>=1) { filename = input.getText().toString(); File sdcard = new File(Environment.getExternalStorageDirectory() + "/VideoRecord"); File from = new File(sdcard,"null.mp4"); File to = new File(sdcard,filename+".mp4"); from.renameTo(to); SharedPreferences sp = videorecord.this.getSharedPreferences("data", MODE_WORLD_WRITEABLE); pre = sp.edit(); pre.clear(); pre.commit(); pre.putString("lastvideo", filename+".mp4"); pre.commit(); //btnplay.setImageResource(android.R.drawable.ic_media_play); btnplay.setImageResource(R.drawable.startrec); // Intent intent = new Intent(videorecord.this,StopVidoWatch_Activity.class); // startActivity(intent); Intent myIntent = new Intent(getApplicationContext(), StopVidoWatch_Activity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(myIntent); } else { filename(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Intent intent = new Intent(videorecord.this,StopVidoWatch_Activity.class); // startActivity(intent); File file = new File(Environment.getExternalStorageDirectory() + "/VideoRecord/null.mp4"); //boolean deleted = file.delete(); file.delete(); finish(); } }); alert.show(); } private boolean prepareMediaRecorder(){ myCamera = getCameraInstance(); mediaRecorder = new MediaRecorder(); myCamera.unlock(); mediaRecorder.setCamera(myCamera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); File folder = new File(Environment.getExternalStorageDirectory() + "/VideoRecord"); boolean success = false; if (!folder.exists()) { success = folder.mkdir(); } if (!success) { } else { } mediaRecorder.setOutputFile("/sdcard/VideoRecord/"+filename+".mp4"); mediaRecorder.setMaxDuration(60000); mediaRecorder.setMaxFileSize(5000000); Display display = getWindowManager().getDefaultDisplay(); int width = display.getHeight(); int height = display.getWidth(); String s = new String(); s= s.valueOf(width); String s1 = new String(); s1= s1.valueOf(height); // Toast.makeText(videorecord.this, "Width : " + s , Toast.LENGTH_LONG).show(); // Toast.makeText(videorecord.this, "Height : " + s1 , Toast.LENGTH_LONG).show(); mediaRecorder.setVideoSize(height, width); mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface()); try { mediaRecorder.prepare(); } catch (IllegalStateException e) { releaseMediaRecorder(); return false; } catch (IOException e) { releaseMediaRecorder(); return false; } return true; } @Override protected void onPause() { super.onPause(); releaseMediaRecorder(); releaseCamera(); } private void releaseMediaRecorder() { if (mediaRecorder != null) { mediaRecorder.reset(); mediaRecorder.release(); mediaRecorder = null; myCamera.lock(); } } private void releaseCamera(){ if (myCamera != null){ myCamera.release(); myCamera = null; } } public class MyCameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback{ private SurfaceHolder mHolder; private Camera mCamera; public MyCameraSurfaceView(Context context, Camera camera) { super(context); mCamera = camera; mHolder = getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceChanged(SurfaceHolder holder, int format, int weight, int height) { if (mHolder.getSurface() == null){ return; } try { mCamera.stopPreview(); } catch (Exception e){ } try { mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (Exception e){ } } public void surfaceCreated(SurfaceHolder holder) { try { mCamera.setPreviewDisplay(holder); mCamera.startPreview(); } catch (IOException e) { } } public void surfaceDestroyed(SurfaceHolder holder) { } } } videorecord.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <FrameLayout android:id="@+id/videoview" android:layout_width="fill_parent" android:layout_height="fill_parent"></FrameLayout> <LinearLayout android:id="@+id/mybutton" android:layout_width="fill_parent" android:layout_marginBottom="0dip" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="0" > <!-- <TextView android:text="START Recording" android:id="@+id/mybutton1" android:layout_height="wrap_content" android:layout_width="wrap_content" style="@style/savestyle" android:layout_weight="1" android:gravity="left" > </TextView> --> <ImageView android:layout_height="wrap_content" android:id="@+id/btnplay" android:padding="5dip" android:background="#A0000000" android:textColor="#ffffffff" android:layout_width="wrap_content" android:src="@drawable/startrec" /> </LinearLayout> <TextView android:text="00:00:00" android:id="@+id/txtcounter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:padding="5dip" android:background="#A0000000" android:textColor="#ffffffff" /> </FrameLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/bgcolor" > <LinearLayout android:layout_above="@+id/mybutton" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" > </LinearLayout> </RelativeLayout> </LinearLayout>

    Read the article

  • Android: Custom ListAdapter extending BaseAdapter crashes on application launch.

    - by Danny
    Data being pulled from a local DB, then mapped using a cursor. Custom Adapter displays data similar to a ListView. As items are added/deleted from the DB, the adapter is supposed to refresh. The solution attempted below crashes the application at launch. Any suggestions? Thanks in advance, -D @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; ViewGroup p = parent; if (v == null) { LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.items_row, p); } int size = mAdapter.getCount(); Log.d(TAG, "position " + position + " Size " + size); if(size != 0){ if(position < size) return mAdapter.getView(position, v, p); Log.d(TAG, "-position " + position + " Size " + size); } return null; } Errors: 03-23 00:14:10.392: ERROR/AndroidRuntime(718): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.AdapterView.addView(AdapterView.java:461) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at com.xyz.abc.CustomSeparatedListAdapter.getView(CustomSeparatedListAdapter.java:90) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.AbsListView.obtainView(AbsListView.java:1273) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.ListView.makeAndAddView(ListView.java:1658) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.ListView.fillDown(ListView.java:637) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.ListView.fillFromTop(ListView.java:694) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.ListView.layoutChildren(ListView.java:1516) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.AbsListView.onLayout(AbsListView.java:1112) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.View.layout(View.java:6569) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.ViewRoot.performTraversals(ViewRoot.java:979) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.os.Handler.dispatchMessage(Handler.java:99) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.os.Looper.loop(Looper.java:123) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.app.ActivityThread.main(ActivityThread.java:4203) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at java.lang.reflect.Method.invokeNative(Native Method) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at java.lang.reflect.Method.invoke(Method.java:521) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 03-23 00:14:10.392: ERROR/AndroidRuntime(718): at dalvik.system.NativeStart.main(Native Method)

    Read the article

  • How can i make a gallery with web images from my website?

    - by ronhdoge
    I currently have two codes that i am trying to figure out how to mix or write a new code to have a gallery with image doing fill_parent but i can slide sideways to see the other url linked images from my site. here are both parts of code i have: package com.mandarich.gallerygrid; import java.io.InputStream; import java.net.URL; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.ImageView; public class Gallery extends Activity { /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView imgView =(ImageView)findViewById(R.id.ImageView01); Drawable drawable = LoadImageFromWebOperations("http://www.mandarichmodels.com/hot-pics/"); imgView.setImageDrawable(drawable); } private Drawable LoadImageFromWebOperations(String url) { try { InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; }catch (Exception e) { System.out.println("Exc="+e); return null; } } } and here is my gallery code package com.mandarich.Grid; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class gridfinal extends Activity { private Gallery gallery; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery = (Gallery) findViewById(R.id.examplegallery); gallery.setAdapter(new AddImgAdp(this)); gallery.setOnItemClickListener(new OnItemClickListener() { @SuppressWarnings("unchecked") public void onItemClick(AdapterView parent, View v, int position, long id) { // Displaying the position when the gallery item in clicked Toast.makeText(gridfinal.this, "Position=" + position, Toast.LENGTH_SHORT).show(); } }); } public class AddImgAdp extends BaseAdapter { int GalItemBg; private Context cont; // Adding images. private Integer[] Imgid = { R.drawable.cindy, R.drawable.clinton, R.drawable.colin, R.drawable.cybil, R.drawable.david, R.drawable.demi, R.drawable.drew }; public AddImgAdp(Context c) { cont = c; TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme); GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); typArray.recycle(); } public int getCount() { return Imgid.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imgView = new ImageView(cont); imgView.setImageResource(Imgid[position]); // Fixing width & height for image to display imgView.setLayoutParams(new Gallery.LayoutParams(430, 370)); imgView.setScaleType(ImageView.ScaleType.FIT_XY); imgView.setBackgroundResource(GalItemBg); return imgView; } } }

    Read the article

  • Select Multiple Images Using GalleryView

    - by hwrdprkns
    Hi guys, I was just wondering if Android had built in code so that I could select multiple images in a gallery-view and then have those images exported as filenames in a string array(ex /sdcard/~f1.jpg, /sdcard/~f2.jpg,...). I have the gallery code here, but I'm not sure what modifications need to be made. Any help is appreciated. Thanks! // take_picture = (Button)findViewById(R.id.take_picture); // Here we set up a string array of the thumbnail ID column we want to // get back String[] proj = { MediaStore.Images.Thumbnails._ID }; if(proj.length == 0) { nopic.setVisibility(View.VISIBLE); } // Now we create the cursor pointing to the external thumbnail store cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, proj, // Which // columns // to // return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) /* take_picture.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(GalleryActivity.this, CameraActivity.class); startActivity(i); } }); */ // We now get the column index of the thumbnail id column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID); // Reference the Gallery view g = (Gallery) findViewById(R.id.gallery); if(proj.length == 0) { nopic.setVisibility(View.VISIBLE); g.setVisibility(View.GONE); } // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { // Now we want to actually get the data location of the file String[] proj = { MediaStore.Images.Media.DATA }; // We request our cursor again cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, // Which // columns // to // return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) // We want to get the column index for the data uri column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Lets move to the selected item in the cursor cursor.moveToPosition((int) g.getSelectedItemId()); // And here we get the filename String filename = cursor.getString(column_index); Log.v("GalleryActivity", filename); Toast.makeText(GalleryActivity.this, filename, Toast.LENGTH_SHORT).show(); setPrefs(filename); Intent i = new Intent(GalleryActivity.this, OtherClass.class); startActivity(i); } }); } And the ImageAdapter code here: public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return cursor.getCount(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(mContext); if (convertView == null) { cursor.moveToPosition(position); int id = cursor.getInt(column_index); i.setImageURI(Uri.withAppendedPath( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + id)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutParams(new Gallery.LayoutParams(200, 200)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); } return i; } } Again any help is appreciateds! Just to let you guys know, the gallery works fine (for one image) as in it exports the filename correctly. Just need to know if there is an easy way to select multiples and export them. Thanks again!

    Read the article

  • Populating a GridView with ImageViews dynamically/programmatically using a ImageAdapter

    - by Julian Vogels
    Hi folks, this is my first question at stackoverflow, but it's a little tricky already... I try to develop an Android App which allows the user to fetch data from flickr and show it in a gridview (with some nice 3D-Animation). After some adventures i got it almost running, but now I'm stuck. Here's the problem: I got a UI Thread "LoadPhotosTask" which gets the pictures from flickr, just like the open source application photostream. In the method onProgressUpdate(LoadedPhoto... value) of that subclass I call addPhoto(). Until now everythings fine - I got some nice Bitmap and Flickr.photo data with all the information I need. @Override public void onProgressUpdate(LoadedPhoto... value) { addPhoto(value); } On the other hand I have got a GridView. Now I want to fill it with the Photos. It has got an adapter called ImageAdapter (which extends BaseAdapter, see this tutorial). If I use an array inside the ImageAdapter class I can populate the GridView with some sample images. But if I want to populate it at runtime, I don't know what to do. How do I have to set up the getView method in the ImageAdapter? I was trying to fill the array inside the ImageAdapter class with my values in addPhoto, but it doesn't display anything. So first of all I was setting up the array with the amount of Photos i wanted to display in the grid like that (code is inside the ImageAdapter class): // class variable private ImageView[] mThumbIds; [...] public void setupArray(int count) { this.mThumbIds = new ImageView[count]; } Then I call this method with the lenght of my photolist: final Flickr.PhotoList list = params[0]; final int count = list.getCount(); int helper = 0; imagead.setupArray(count); Afterwards I call the getView method manually inside the addPhoto method: private void addPhoto(LoadedPhoto... value) { ImageView image = (ImageView) mInflater.inflate( R.layout.grid_item_photo, null); image.setImageBitmap(value[0].mBitmap); image.setTag(value[0].mPhoto); imagead.setmThumbIds(image, value[0].mPosition); imagead.getView(value[0].mPosition, null, mpicturesGrid); } That is the getView method inside ImageAdapter: public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { // if it's not recycled, initialize some // attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(EDGE_LENGTH, EDGE_LENGTH)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(0, 0, 0, 0); imageView.setVisibility(View.VISIBLE); } else { imageView = (ImageView) convertView; } imageView.setImageDrawable(mThumbIds[position].getDrawable()); imageView.setTag(mThumbIds[position].getTag()); return imageView; } Ok, finally I apologize for my poor english and I hope you can give me some help with the information I provided. Greetings, Julian

    Read the article

  • How to refresh a GridView?

    - by Daniel
    Hello everyone, I have a GridView which is pretty similar to the Google tutorial, except that I want to add the ImageViews on runtime (via a subactivity). The results are okay, but the layout of the View is messed up: The GridView doesn't fill the content of its parent, what do I have to do to design it properly? Here the code of adding the children: public void initializeWorkbench(GridView gv, Vector<String> items) { Prototype.workbench.setDimension(screenWidth, divider.height()+workbenchArea.height()); Prototype.workbench.activateWorkbench(); // this measures the workbench correctly Log.d(Prototype.TAG, "workbench width: "+Prototype.workbench.getMeasuredWidth()); // 320 Log.d(Prototype.TAG, "workbench height: "+Prototype.workbench.getMeasuredHeight()); // 30 ImageAdapter imgAdapter = new ImageAdapter(this.getContext(), items); gv.setAdapter(imgAdapter); gv.measure(screenWidth, screenHeight); gv.requestLayout(); gv.forceLayout(); Log.d(Prototype.TAG, "gv width: "+gv.getMeasuredWidth()); // 22 Log.d(Prototype.TAG, "gv height: "+gv.getMeasuredHeight()); // 119 Prototype.workbench.setDimension(screenWidth, divider.height()+workbenchArea.height()); } } activateWorkbench, setDimension and measure in the workbench (LinearLayout above the GridView): public void activateWorkbench() { if(this.equals(Prototype.workbench)) { this.setOrientation(VERTICAL); show = true; measure(); } } public void setDimension(int w, int h) { width = w; height = h; this.setLayoutParams(new LinearLayout.LayoutParams(width, height)); this.invalidate(); } private void measure() { if (this.getOrientation() == LinearLayout.VERTICAL) { int h = 0; int w = 0; this.measureChildren(0, 0); for (int i = 0; i < this.getChildCount(); i++) { View v = this.getChildAt(i); h += v.getMeasuredHeight(); w = (w < v.getMeasuredWidth()) ? v.getMeasuredWidth() : w; } if (this.equals(Prototype.tagarea)) height = (h < height) ? height : h; if (this.equals(Prototype.tagarea)) width = (w < width) ? width : w; } this.setMeasuredDimension(width, height); } The ImageAdapter constructor: public ImageAdapter(Context c, Vector<String> items) { mContext = c; boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else { // Something else is wrong. It may be one of many other states, but // all we need // to know is we can neither read nor write mExternalStorageAvailable = mExternalStorageWriteable = false; } if (mExternalStorageAvailable && mExternalStorageWriteable) { for (String item : items) { File f = new File(item); if (f.exists()) { try { FileInputStream fis = new FileInputStream(f); Bitmap b = BitmapFactory.decodeStream(fis); bitmaps.add(b); files.add(f); } catch (FileNotFoundException e) { Log.e(Prototype.TAG, "", e); } } } } } And the xml layout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:gravity="bottom" android:paddingLeft="0px" android:paddingTop="0px" android:paddingRight="0px"> <com.unimelb.pt3.ui.TransparentPanel android:id="@+id/workbench" android:layout_width="fill_parent" android:layout_height="10px" android:paddingTop="0px" android:paddingLeft="0px" android:paddingBottom="0px" android:paddingRight="0px"> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> </com.unimelb.pt3.ui.TransparentPanel> </LinearLayout>

    Read the article

  • Saving to SharedPreferences from custom DialogPreference

    - by Ronnie
    I've currently got a preferences screen, and I've created a custom class that extends DialogPreference and is called from within my Preferences. My preferences data seems store/retrieve from SharedPreferences without an issue, but I'm trying to add 2 more sets of settings from the DialogPreference. Basically I have two issues that I have not been able to find. Every site I've seen gives me the same standard info to save/restore data and I'm still having problems. Firstly I'm trying to save a username and password to my SharedPreferences (visible in the last block of code) and if possibly I'd like to be able to do it in the onClick(). My preferences XML that calls my DialogPreference: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory> <com.rone.optusmon.AccDialog android:key="AccSettings" android:title="Account Settings" android:negativeButtonText="Cancel" android:positiveButtonText="Save" /> </PreferenceCategory> </PreferenceScreen> My Preference Activity Class: package com.rone.optusmon; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; import android.view.KeyEvent; public class EditPreferences extends PreferenceActivity { Context context = this; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } } My Custom DialogPreference Class file: package com.rone.optusmon; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.preference.DialogPreference; import android.preference.PreferenceManager; import android.text.method.PasswordTransformationMethod; import android.util.AttributeSet; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class AccDialog extends DialogPreference implements DialogInterface.OnClickListener { private TextView mUsername, mPassword; private EditText mUserbox, mPassbox; CharSequence mPassboxdata, mUserboxdata; private CheckBox mShowchar; private Context mContext; private int mWhichButtonClicked; public AccDialog(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } @Override protected View onCreateDialogView() { @SuppressWarnings("unused") LinearLayout.LayoutParams params; LinearLayout layout = new LinearLayout(mContext); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(10, 10, 10, 10); layout.setBackgroundColor(0xFF000000); mUsername = new TextView(mContext); mUsername.setText("Username:"); mUsername.setTextColor(0xFFFFFFFF); mUsername.setPadding(0, 8, 0, 3); mUserbox = new EditText(mContext); mUserbox.setSingleLine(true); mUserbox.setSelectAllOnFocus(true); mPassword = new TextView(mContext); mPassword.setText("Password:"); mPassword.setTextColor(0xFFFFFFFF); mPassbox = new EditText(mContext); mPassbox.setSingleLine(true); mPassbox.setSelectAllOnFocus(true); mShowchar = new CheckBox(mContext); mShowchar.setOnCheckedChangeListener(mShowchar_listener); mShowchar.setText("Show Characters"); mShowchar.setTextColor(0xFFFFFFFF); mShowchar.setChecked(false); if(!mShowchar.isChecked()) { mPassbox.setTransformationMethod(new PasswordTransformationMethod()); } layout.addView(mUsername); layout.addView(mUserbox); layout.addView(mPassword); layout.addView(mPassbox); layout.addView(mShowchar); return layout; // Access default SharedPreferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); } public void onClick(DialogInterface dialog, int which) { mWhichButtonClicked = which; // if statement to set save/cancel button roles if (mWhichButtonClicked == -1) { Toast.makeText(mContext, "Save was clicked", Toast.LENGTH_SHORT).show(); mUserboxdata = mUserbox.getText(); mPassboxdata = mPassbox.getText(); // Save user preferences SharedPreferences settings = getDefaultSharedPreferences(this); SharedPreferences.Editor editor = settings.edit(); editor.putString("usernamekey", (String) mUserboxdata); editor.putString("passwordkey", (String) mPassboxdata); } else { Toast.makeText(mContext, "Cancel was clicked", Toast.LENGTH_SHORT).show(); } } } In my SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); line, Eclipse says "The method getDefaultSharedPreferences(AccDialog) is undefined for the type AccDialog". I've attempted to change the context to my preferences class, use a blank context and I've also tried naming my SharedPrefs and using "getSharedPreferences()" as well. I'm just not sure exactly what I'm doing here. As I'm quite new to Java/Android/coding in general, could you please be as detailed as possible with any help, eg. which of my files I need to write the code in and whereabouts in that file should I write it (i.e. onCreate(), onClick(), etc) Edit: I will need to the preferences to be Application-wide accessible, not activity-wide. Thanks

    Read the article

< Previous Page | 2 3 4 5 6