Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Intent twice the same activity in OnTouch method?
    primarykey
    data
    text
    <p>When I touch the screen, the OnTouch method is called twice. So the Intent of the new activity in the method "showdetails" load the activity with the view associated twice also. Why? I just need one...</p> <pre><code>public class DeptFragment extends Fragment implements OnTouchListener { Context mContext = getActivity(); ImageView cacheImage,targetImage; ListView List; ArrayList&lt;String&gt; tabDepartement; ArrayList&lt;String&gt; tabCommunes; int codeDepartementCrt; Departement DepartementCrt; List&lt;Commune&gt; listCommuneCrt; Bundle nomBundle; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState) ; return inflater.inflate(R.layout.dept_fragment, container, false); } @Override public void onActivityCreated(Bundle savedState) { super.onActivityCreated(savedState); mContext=getActivity(); View mView = getView(); targetImage = (ImageView) mView.findViewById(R.id.targetDeptImage); targetImage.setOnTouchListener(this); } public boolean onTouch(View v, MotionEvent event) { View mView = getView(); ImageView imageView = (ImageView) mView.findViewById(R.id.cacheDeptImage); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); int pixel = bitmap.getPixel((int) event.getX(),(int) event.getY()); int redValue = Color.red(pixel); int blueValue = Color.blue(pixel); int greenValue = Color.green(pixel); showDetails(redValue,greenValue,blueValue); return true; </code></pre> <p>}</p> <pre><code>/** * Helper function to show the details of a selected item, by starting a * whole new activity in which it is displayed. */ void showDetails(int red, int green, int blue) { DepartementCrt=rechercherDepartement(red,green,blue); if (DepartementCrt != null) { Intent intent = new Intent(); intent.setClass(getActivity(), DeptDetailActivity.class); intent.putExtra("code", DepartementCrt.Code); startActivity(intent); } } private Departement rechercherDepartement(int redValue, int greenValue, int blueValue) { DepartementRepository departementRepository=new DepartementRepository(mContext); Departement departement; departementRepository.Open(); departement= departementRepository.rechercherDepartement(redValue, greenValue, blueValue); departementRepository.Close(); return departement; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload