logo
down
shadow

Always on top ImageView


Always on top ImageView

By : hpeide
Date : November 22 2020, 10:40 AM
it helps some times I've now used this Chathead method.
code :


Share : facebook icon twitter icon
Android looping through an array of ImageView and calling a function that takes the ImageView as argument

Android looping through an array of ImageView and calling a function that takes the ImageView as argument


By : Duy Ngan Nguyen
Date : March 29 2020, 07:55 AM
To fix this issue You should be able to access the pieces variable inside the Runnable (because it is final), what you won't be able to access is the i variable. You can do this: final int index = i and use index instead of i inside the run() method. Also, you may want to increase the delay for each image, otherwise all the operations will be executed almost at the same time.
code :
for(int i = 0; i < pieces.length; i++) {
        final int index = i;
        Runnable shuffle = new Runnable() {
            public void run() {
                playLevel(pieces[index]);
            }
        };
        handler.postDelayed(shuffle, (i+1)*3000);
}
How do I make imageView respond to double tap and recognize when imageView is pressed, unpressed(action down, up)?

How do I make imageView respond to double tap and recognize when imageView is pressed, unpressed(action down, up)?


By : Ali
Date : March 29 2020, 07:55 AM
it helps some times after struggling so much with gesture listener and its methods - onFling, onLongPress etc I decided to write my own, my idea is not that different from recording the time of of each press, there is similar solution on SO.
I understand what my problem was: if you use onTouch - all your touches are intercepted and interpreted through it, but simpleGestureListener processes its own events through onDown, so onTouch is never called; in this situation I had to write pretty basic logic:
code :
public class DoubleTapWorking1 extends Activity implements View.OnTouchListener {
ImageView sample;
boolean still_down ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sample = (ImageView) findViewById(R.id.sample);
    sample.setOnTouchListener(this);
    still_down = false ;

}

@Override
public boolean onTouch(final View v,final MotionEvent e) {

     switch (e.getAction()){
         case MotionEvent.ACTION_DOWN:
             still_down =false;
             CountDownTimer timer = new CountDownTimer(500,10){
                 @Override
                 public void onTick(long millisUntilFinished) {
                     if((int)millisUntilFinished < 100 && e.getAction() == MotionEvent.ACTION_DOWN){
                         still_down = true ;
                     }
                 }
                 @Override
                 public void onFinish() {
                     if( still_down){                           
                         //code to make imageView larger
                     }
                 }
             }.start();
             break ;
         case MotionEvent.ACTION_UP:
             if(still_down) {
                 //your code to make image smaller
             }
             else{
                 action_on_single_tap(v);
             }
             break ;
     }

   return true;
  }

  private void action_on_single_tap(final View v){
      //your code to do with image on single tap - move somewhere else, make invisible etc.
}
private class Gestures_future implements View.OnClickListener, View.OnLongClickListener{

     int margin_long_press_x1;
     int margin_long_press_y1;
     int margin_long_press_x2;
     int margin_long_press_y2;
     RelativeLayout.LayoutParams params_generic = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
public Gestures_future(final int margin_long_press_x1,final int margin_long_press_y1,final int margin_long_press_x2,final int margin_long_press_y2
    ){
        params_generic.leftMargin = 30;
        params_generic.topMargin = 40;

        this.margin_long_press_x1 = margin_long_press_x1;
        this.margin_long_press_y1 = margin_long_press_y1;
        this.margin_long_press_x2 = margin_long_press_x2;
        this.margin_long_press_y2 = margin_long_press_y2;
    }
    @Override
    public void onClick(View v) {
        Log.wtf("x", "on click!");
        TextView d = (TextView)v;
        int current_id = v.getId();
       String answer_content = d.getText().toString();
        if (answers_player1_ids.contains(current_id)) {
        if (Battlefield.getStateOfAnswer1PlacePlayer1() == false) {
            d.setText("");
            Battlefield.answer1_place_busy_player1 = true;
            answer_place1_player1.setTextSize(20);
            answer_place1_player1.setText(answer_content);
            upper_layout_answer_counter++;
        } else if (Battlefield.getStateOfAnswer2PlacePlayer1() == false) {
            d.setText("");
            Battlefield.answer2_place_busy_player1 = true;
            answer_place2_player1.setTextSize(20);
            answer_place2_player1.setText(answer_content);
            upper_layout_answer_counter++;
            if (upper_layout_answer_counter == 2) {
                upper_layout_answer_counter = 0;
                see_answers1.performClick();
            }
        }
    }
        else if (answers_player2_ids.contains(current_id)) {
        if (Battlefield.getStateOfAnswer1Place() == false){
            d.setText("");
            Battlefield.answer1_place_busy = true;
            answer_place1.setTextSize(20);
            answer_place1.setText(answer_content);
            lower_layout_answer_counter++;
        } else if (Battlefield.getStateOfAnswer2Place() == false) {
            d.setText("");
            Battlefield.answer2_place_busy = true;
            answer_place2.setTextSize(20);
            answer_place2.setText(answer_content);
            lower_layout_answer_counter++;
            if (lower_layout_answer_counter == 2) {
                lower_layout_answer_counter = 0;
                see_answers2.performClick();
            }
        }
    }
}
    @Override
    public boolean onLongClick(View v){
        Log.wtf("x", "on long click!");
        final TextView d = (TextView)v;
        Log.wtf("x", d.getText().toString() +  " long clicked!" );
                    d.setTextSize(30);
                    RelativeLayout.LayoutParams x = new RelativeLayout.LayoutParams(350, 500);
                    x.setMargins(margin_long_press_x1, margin_long_press_y1, 0, 0);
                    d.setLayoutParams(x);
                    d.requestLayout();
        new CountDownTimer(3000,500){
            @Override
            public void onTick(long millisUntilFinished) {
            }
            @Override
            public void onFinish() {
                RelativeLayout.LayoutParams t1 = new RelativeLayout.LayoutParams(130, 170);
                t1.setMargins(margin_long_press_x2, margin_long_press_y2, 0, 0);
                d.setTextSize(10);
                d.setLayoutParams(t1);
                d.requestLayout();
            }
        }.start();
        return true;
    }

}
get image from ImageView to another imageView in second activity when click on 1st imageview

get image from ImageView to another imageView in second activity when click on 1st imageview


By : M.Verm
Date : March 29 2020, 07:55 AM
it helps some times I want to get image from ImageView to another imageView in second activity when click on 1st imageview , In Activity 1:
code :
    ImageView imageView = (ImageView) findViewById(R.id.fort_image);
    imageView.setImageResource(R.drawable.killa_ahmednagar_bhuikot_fort);

    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent myIntent = new Intent(getApplicationContext(), FullscreenImageActivity.class);
            myIntent.putExtra("Drawable", R.drawable.killa_ahmednagar_bhuikot_fort);
            startActivity(myIntent);
        }
    });
    Intent intent = getIntent();
    int drawable = intent.getIntExtra("Drawable", 0); 
    imageView.setImageResource(drawable);
Pick image from gallery and load it into the imageview of the particular activity and into a navigation drawer imageview

Pick image from gallery and load it into the imageview of the particular activity and into a navigation drawer imageview


By : Glenn Skerman
Date : March 29 2020, 07:55 AM
How to set ImageView setOnClickListner which is in custom listview and play/pause song when Imageview clicked?

How to set ImageView setOnClickListner which is in custom listview and play/pause song when Imageview clicked?


By : Koketa
Date : March 29 2020, 07:55 AM
will be helpful for those in need First Add a interface in your adapter class like & use it like this ::
code :
public class SongAdapter extends BaseAdapter {

    Context context;
    private ArrayList<SongModel> songsListDat = null;
    public ArrayList<SongModel> songsList;
    public OnMusicListener mListener;
    private static LayoutInflater inflater;

    public SongAdapter(Activity activity, ArrayList<SongModel> songsListDat, OnMusicListener mListener) {

        this.context = activity;
        this.mListener = mListener;
        this.songsListDat = songsListDat;
        this.songsList = new ArrayList<SongModel>();
        this.songsList.addAll(songsListDat);
    }

    public void setSelectedIndex(int ind) {
        notifyDataSetChanged();
    }

    @Override
    public int getViewTypeCount() {

        return 1;
    }

    @Override
    public int getCount() {
        return songsListDat.size();
    }

    @Override
    public Object getItem(int position) {
        return songsListDat.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {

        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View vi = convertView;
        if (convertView == null)
            vi = inflater.inflate(R.layout.ringtone_row_layout, null);

        TextView title = (TextView) vi.findViewById(R.id.name); // title
        ImageView play = (ImageView) vi.findViewById(R.id.imgPlayPause);
        ImageView pause = (ImageView) vi.findViewById(R.id.imgPause);


        SongModel song = new SongModel();
        song = songsListDat.get(position);
        title.setText(song.getSongTitle());

        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onPlayClicked(position);
            }
        });
        pause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onPauseClicked(position);
            }
        });

        return vi;
    }

    public interface OnMusicListener {
        void onPauseClicked(int position);

        void onPlayClicked(int position);
    }
}
songAdapter = new SongAdapter(this, songsList,this);
setListAdapter(songAdapter);
public class MainActivity extends ListActivity implements SongAdapter.OnMusicListener{

    public static final String TAG = "[MainActivity]";

    Activity activity;
    SongAdapter songAdapter;
    SongsManager songsManager = new SongsManager();
    MediaPlayer mp;

    // Songs list
    public ArrayList<SongModel> songsList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        activity = MainActivity.this;


        mp = new MediaPlayer();


        SongsManager plm = new SongsManager(activity);
        final ArrayList<SongModel> songsListData = songsManager.songList;


        this.songsList = plm.getAllSongs();


        for (int i = 0; i < songsListData.size(); i++) {
            SongModel song = songsListData.get(i);
            songsListData.add(song);
        }


        songAdapter = new SongAdapter(this,songsList,this);
        setListAdapter(songAdapter);

        ListView lv = getListView();

    }

    @Override
    public void onPauseClicked(int position){

          //Todo-- Add code you want to perform on Pause clicked with   specific position

    }
    @Override
    public onPlayClicked(int position){
         //Todo-- Add code you want to perform on Play clicked with   specific position
    }
}
Related Posts Related Posts :
  • Stream corrupted exception - invalid code type AC [java]
  • Routing Sysout values to JTextArea
  • GWT RPC serialization for Dynamic Host Page
  • Best Approch of Returning Value from 'getter' Method
  • Understanding xml schemalocation
  • Checking if a PDF is PDF/A 1-a format or not using PDFBOX in java
  • Difference Between Variable and Identifier
  • How to compute two aggregate functions with Java streams?
  • Parse the value of the json to baseadapter in android?
  • JavaFX animation on raspberry pi
  • Solve "unchecked warning" in Java avoiding @suppressWarnings
  • How to specify a new name for a file while moving it to another directory in Java?
  • Popup window not showing up with spinner item selection?
  • how to iterate through json objects in java
  • Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor
  • Getting NoClassDefFoundError while running PMD task from Gradle
  • Matlab drag and drop file from windows explorer to figure (gui)
  • How does scala's actor model make use of C threads and native system threads?
  • Store java.util.Date as key in a Map based on reference equality instead of "value" equality
  • Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient
  • creating unique index in mongoDB
  • hibernate Query to find record based on substring
  • How many strings are in jvm string pool intern
  • Unable to initialize native-platform. on Jenkins
  • How to create a list of dummy files in Java?
  • Docker: Which approach is better? WAR embedded in image or base image + war?
  • java.lang.InternalError: CallerSensitive annotation expected at frame 1
  • How to write a method to read JSON files of different structures and return different POJO objects in Java?
  • Reference to Classes in Java
  • Unable to call function via companion object
  • REST: convert XML content passed with POST to a java object, attribute inside the element
  • Device not receive message from GCM
  • How to increase Openfire concurrent connection limit?
  • Android send custom parameter on AsyncTask
  • GWT - Get dom element's value from another page
  • How can i initialize an array in Java?
  • Is it possible to increase a java process's(when is running) size?
  • Getting Node Address instead of Value in Binary Search Tree
  • PdfByteContent not adding in iText pdf
  • Spring JpaRepository: delete() with subsequent save() in the same transaction
  • producer-consumer using arraydeque working only in breakpoint
  • Adding a JPanel to another JPanel
  • Comparison with operator ==, how does it work?
  • Error buildling with maven for openshift
  • What is the java equivilant to MySQL's smallint
  • proxy trouble on eclipse with https
  • Spring-Jdbc Template and Prepared statement
  • Mule - exception in Outbound endpoint Message payload is of type: byte[]
  • Modify package names for java classes generated from wsdl
  • How to download multiple images and have one progressBar using AsynTask (Android)
  • Implementing Service Provider, IdP and user in java with SAML (POC)
  • Why does my scanner repeat?
  • Can I forget ResultSetFuture in Cassandra java driver without facing memory leak?
  • XML to JAXB binding having nested elements?
  • Java: ToString() prints the same hashcode each time
  • Why am I getting a thread exception in my graphics program?
  • Can we read 4th byte from hexadecimal value?
  • How to create watermark in image just like Google maps watermarks
  • how come Thread class called inside another class?
  • AssertionError: Unexpected schema version 0: Unexpected schema version 0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org