Been scratching my head on this one. I have the following code which simply looks at a pixel and identifies its color. Should it be a certain color, it will call an alert to pop up.
public void setClick(final View view)
{
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (count == 0) {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
if (Color.red(bitmap.getPixel((int) event.getX(), (int) event.getY())) == 232) {
alert();
count++;
}
The XML for the onTouchListener is as follows.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/silLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/cust_scroll"
android:layout_width="237dp"
android:layout_height="558dp"
android:background="@drawable/silhoutte_front_ii"
android:duplicateParentState="true"
android:clickable="true"
android:onClick="setClick"
android:layout_gravity="center"/>
<Button
android:id="@+id/toCustomize"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Next >>"
android:onClick="toCustomize"/>
</LinearLayout>
The alert is constructed as follows.
public void alert(){
LayoutInflater inflater= LayoutInflater.from(this);
View view=inflater.inflate(R.layout.alert_scroll, null);
TextView textview=(TextView)view.findViewById(R.id.textmsg);
textview.setText("Your really long message.");
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Title");
//alertDialog.setMessage("Here is a really long message.");
alertDialog.setView(view);
alertDialog.setPositiveButton("OK", null);
alertDialog.setNegativeButton("cancel", null);
AlertDialog alert = alertDialog.create();
alert.show();
}
The XML for the alert is as follows.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textmsg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="hello" />
</LinearLayout>
</ScrollView>
Now, when the correct color is identified, the alert pops up no problem. Afterwards, however, the onTouchListener stops responding and will no longer call the alert. I understand that in the title I said the onClickListerns are breaking and this is an onTouchListener, but I have this very same issue elsewhere with an onClickListener. I cannot find any information on the subject but I know there is a simple solution. Thanks in advance.