Textview cannot be cast to android.widget.listview - java

I believe to have the textview, but it cannot be cast to listview error in the following code below:
Essentially I am trying to populate information from Parse into a textfield. This I believe is the part of the code that is problematic.
here it throws a "textview cannot be cast to android.widget.listview"
public void done(List<ParseUser> userlistactivityname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivityname.size(); i++) {
mUserActivityNameRetrieved = (TextView) getActivity().findViewById(R.id.userlistactivityname);
mUserActivityNameRetrieved.setText(userlistactivityname.get(i).get("ActivityName").toString());
}
} else {
//else..
}
}
Below is the XML code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/blue_bac3"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/profilePictureresult"
android:layout_marginTop="16dp"
android:alpha="0.7"
android:src="#drawable/left_right" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView2"
android:alpha="0.7"
android:src="#drawable/left_arrow2" />
<TextView
android:id="#+id/userlistactivityname"
android:layout_width="220dp"
android:layout_height="50dp"
android:cacheColorHint="#android:color/transparent"
android:layout_below="#+id/textView1"
android:layout_toLeftOf="#+id/imageView2"
android:divider="#null" >
</TextView>
<ListView
android:id="#+id/userlistheadline"
android:layout_width="280dp"
android:layout_height="90dp"
android:layout_below="#+id/userlistname"
android:layout_centerHorizontal="true"
android:cacheColorHint="#android:color/transparent"
android:divider="#null"
android:textAlignment="center" >
</ListView>
<com.parse.ParseImageView
android:id="#+id/profilePictureresult"
android:layout_width="132dp"
android:layout_height="120dp"
android:layout_below="#+id/userlistheadline"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:alpha="1"
android:background="#drawable/border_image"
android:cropToPadding="true"
android:padding="3dp"
android:scaleType="centerCrop" />
<ListView
android:id="#+id/userlistage"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_below="#+id/profilePictureresult"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:divider="#null" >
</ListView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/userlistage"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:text="Activity Name"
android:textColor="#d2f2a2"
android:textSize="23sp"
android:textStyle="bold" />
<Button
android:id="#+id/btnMatchConfirm"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#+id/userlistactivityname"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:alpha="0.7"
android:background="#ADD8E6"
android:text="Confirm"
android:textColor="#000000"
android:textSize="22sp"
android:typeface="serif" />
<TextView
android:id="#+id/userlistname"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:cacheColorHint="#android:color/transparent"
android:clickable="false"
android:divider="#null"
android:drawSelectorOnTop="false"
android:fadingEdge="vertical|none"
android:fastScrollAlwaysVisible="false"
android:fastScrollEnabled="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:listSelector="#android:color/transparent"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbars="vertical|none"
android:scrollingCache="false"
android:smoothScrollbar="false"
android:textAlignment="gravity" >
</TextView>
Thanks in advance.

you have used the ID "userlistactivityname" more than once, e.g. you define a textview and give it the id userlistactivityname, but later you also have a button with the same id "userlistactivityname"
<TextView
android:id="#+id/userlistactivityname"
...
android:divider="#null" >
</TextView>
<Button
android:id="#+id/btnMatchConfirm"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#+id/userlistactivityname"
...
android:typeface="serif" />
and maybe you even have another widget defined as "userlistactivityname".
Search all your layouts for "userlistactivityname" and make sure that the id is unique!

When you want a view to be below / above / leftOf another view, you reference the view using the code
#id/view_id
when you want to add a new id to the Android R file, you use the code
#+id/new_view_id
if you use #+id/ all the time, you can create problems in your R file. Try changing all references in your code to make it cleaner, and only using #+id/ when specifying android:id
<Button
android:id="#+id/btnMatchConfirm"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#id/userlistactivityname"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:alpha="0.7"
android:background="#ADD8E6"
android:text="Confirm"
android:textColor="#000000"
android:textSize="22sp"
android:typeface="serif" />

Related

How to start code when pressed four Buttons in Android

I want to make pin input with Buttons and TextView in Android.
I have Textview for pin , and 9 Buttons for user to press as digits.
What i want when user press four buttons to change my Textview letter by letter(Button by Button) , and when entered fourth button to start code
Here is image:
Any tips please?
Here is my code:
content_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.group.digit.razvoj.appointment.MainActivity"
tools:showIn="#layout/app_bar_main">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/pinLayoutMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:orientation="vertical"
android:paddingRight="#dimen/left_margin_pin">
<LinearLayout
android:id="#+id/pinTvLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/between_margin"
android:layout_marginTop="#dimen/between_margin"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/pinTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/pin"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/passLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="50dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/pinEntry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="****"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/firstRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/b1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="2"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="3"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/secondRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/b4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="4"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="5"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b6"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="6"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/sthirdRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/b7"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="7"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b8"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="8"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b9"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="9"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/forthow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b0"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="0"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/bback"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="-"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
MainActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init buttons
for (int i = 0; i < MAX_PIN_NUM; i++) {
buttonsPinWidget[i] = (Button) findViewById(buttonsPinId[i]);
}
pinentry = (TextView) findViewById(R.id.pinEntry);
}
You should to use one onClickListener for everyone button with switch case inside of it.
In every case of switch case block your should addor delete (if you have the button for deleting) one character it TextView.
After switch case block check the text length in your TextView. If the length of it equals 4, you can try to authorization or login or other actions.
Sorry for bad English.
Very interesting question first of all.
The only solution I can think of is to create a public method which will always check the length of the textview (which I think should be edittext) and add that method for every button. Once the length of the textview is 4, trigger your code you want.
Let me know if you need some more clarification
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String s=txtView.getText().toString();
if(s.length()<3){
s=s+btn.getText().toString();
txtView.setText(""+s);
}else if(s.length()==3){
s=s+btn.getText().toString();
txtView.setText(""+s);
// write your code
}
}
});

Android textview text underline unwanted

I'm having a strange trouble and didn't find any solutions on the web.
I'm adding a TextView dynamically into a RelativeLayout, with custom fonts, and sometimes the text appears underlined.
public void bouton_valide_ajout_texte(View v)
{
new_text_view.setText(((TextView) dialog.findViewById(R.id.edit_ajoute_texte)).getText());
RelativeLayout rl_newtext_1 = (RelativeLayout)findViewById(R.id.rl_newtext_1);
rl_newtext_1.addView(new_text_view);*/
TextView text_view = new TextView(this);
text_view.setText(((TextView) dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText());
ListView liste_view_police = (ListView) dialog_ajoute_texte.findViewById(R.id.list_view_dialog_polices);
text_view.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
text_view.setTypeface(listePolices.get_typeface(position_item_police));
text_view.setTextColor(Color.argb(255, 0, 0, 0));
text_view.clearComposingText();
container_calques.addView(text_view);
Object[] tab_calque = new Object[5];
tab_calque[0]="texte";
tab_calque[1]=text_view;
tab_calque[2]=12;
tab_calque[3]=0;
liste_calques.add(tab_calque);
calque_selectionne=liste_calques.size()-1;
text_view.setOnTouchListener(new TouchListener_calque(liste_calques.size()-1));
dialog_ajoute_texte.hide();
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ebm="http://schemas.android.com/apk/res-auto"
xmlns:sat="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="350dp"
android:layout_gravity="center"
android:id="#+id/rl_container_tshirt">
<ImageView
android:id="#+id/tshirt_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/tee_shirt_blanc">
</ImageView>
<RelativeLayout
android:id="#+id/container_calques"
android:layout_width="120dp"
android:layout_height="220dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="85dp"
>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layout_reglages_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
>
<SeekBar
android:id="#+id/seekbar_taille"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:max="40"
android:progress="20"
/>
<SeekBar
android:id="#+id/seekbar_rotation"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:layout_alignParentLeft="true"
android:max="360"
android:progress="180"
/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Supprimer"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:onClick="bouton_supprimer_calque"/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Couleur"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:onClick="bouton_choisir_couleur"/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Police"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_marginTop="80dp"
android:onClick="bouton_choisir_police"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="ajouter texte"
android:id="#+id/ajouter_calque"
android:onClick="bouton_ajoute_texte"/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="ajouter image"
android:id="#+id/ajouter_image"
android:onClick="bouton_ajoute_image"
android:layout_alignParentRight="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="enregistrer création dans galerie"
android:id="#+id/enregistrer_creation"
android:onClick="bouton_enregistrer_creation"
android:layout_below="#+id/ajouter_calque"
/>
</RelativeLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.view.ext.SatelliteMenu
android:id="#+id/menu_flottant_gauche"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_margin="8dp"
sat:satelliteDistance="170dp"
sat:mainImage="#drawable/ic_launcher"
sat:totalSpacingDegree="90"
sat:closeOnClick="true"
sat:expandDuration="200"
/>
</FrameLayout>
</LinearLayout>
Solved
I replaced
text_view.setText(((TextView);
dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText());
By
text_view.setText(((EditText);
dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText().toString());
The possible underline could by the ListView as it puts a divider between its items. Look at this answer to get rid of the divider
Please make sure you don't have any inputType to your textview as follows
android:inputType="something"

Load images from tableLayout android

I have five rows imageView, but this code load only 4 rows? why?
Java code
tl = (TableLayout) findViewById(R.id.tableLayout);
for (int i = 0; i < tl.getChildCount(); i++) {
View v = tl.getChildAt(i);
if (v instanceof TableRow) {
for (int j = 0; j < ((TableRow) v).getChildCount(); j++) {
View innerView = ((TableRow) v).getChildAt(j);
if (innerView instanceof ImageView) {
imageList.add((ImageView) innerView);
idList.add(innerView.getId());
}
}
}
}
Layout
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="true"
android:layout_marginBottom="275dp"
android:id="#+id/tableLayout">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView25"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView5"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView13"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView12"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView11"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView10"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView14"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView9"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView8"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView6"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView7"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView18"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView17"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView16"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView15"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView19"
android:layout_column="6"
android:nestedScrollingEnabled="false"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView23"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView22"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView21"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView20"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView24"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
</TableLayout>
I can comparing two imageView? eg
image.get(1).getdrawable()==image.get(2).getdrawable()?
No, by this way it just comparing whether they are the same object or not. In this case this will be false. But, if you want to compare the images of the imageviews, then you should get theirs bitmap then use sameAs method.
//comapre objects returns false
Log.i("EQ", (imageList.get(0).getDrawable().equals(imageList.get(1).getDrawable())) + "");
Log.i("EQ", imageList.get(0).getDrawable().toString()); //android.graphics.drawable.BitmapDrawable#89c323c
Log.i("EQ", imageList.get(1).getDrawable().toString()); //android.graphics.drawable.BitmapDrawable#837dbc5
BitmapDrawable bitmapDrawable0 = ((BitmapDrawable) imageList.get(0).getDrawable());
Bitmap bitmap0 = bitmapDrawable0 .getBitmap();
BitmapDrawable bitmapDrawable1 = ((BitmapDrawable) imageList.get(1).getDrawable());
Bitmap bitmap1 = bitmapDrawable1 .getBitmap();
//comapre the image returns true
Log.i("EQ2", Boolean.toString(bitmap0.sameAs(bitmap1)));
Where i called toString() it shows that, they are not the same object, although they are holding the same image as sameAs indicating.
Note:
instead of equals() method, "==" operator would do the same, there is no difference

Android: onClick event listener doesn't work on linearlayout

I am trying to implement an onclick for the entire layout but it won't work.
Here is my function for my RelativeLayout:
public void updateRange(View v)
{
System.out.println("Hello!");
}
and here is my 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="wrap_content"
tools:context=".MainActivity"
android:background="#ffffffff"
android:id="#+id/xasdf"
android:onClick="updateRange">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/toptab"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/settingsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solutions"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/solutionsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mode"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/modeButton"
android:background="#fffdb64b" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/chartlayout"
android:layout_below="#+id/toptab"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView"
android:layout_weight="0.5"
android:background="#ffffffff"
android:fontFamily="monospace"
android:hint="y = ..." />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Graph"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.25"
android:id="#+id/button"
android:background="#ffd0d0d0"
android:onClick="drawGraph" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Table"
android:fontFamily="monospace"
android:layout_weight="0.25"
android:textAllCaps="false"
android:id="#+id/button2"
android:background="#ffd0d0d0" />
</LinearLayout>
</RelativeLayout>
Try adding the extra line below to your Relative Layout description:
...
android:onClick="updateRange"
android:clickable="true">

ListView row not clickable (after adding two buttons)

Strangely, my listView's onClick no longer works after I added two Buttons: Submit and Show Result.
Here is the list view xml.
<RelativeLayout 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"
tools:context=".CulturalActivity"
android:background="#EFEFEF"
android:id="#+id/AdLayout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#android:color/transparent"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
Here is the layout of each list row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:background="#drawable/bg_card"
android:orientation="horizontal"
android:padding="5dip" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="-60dp"
android:background="#2093CD"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="52dp"
android:text="Audit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout2" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Farm/Grp"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignTop="#+id/tile"
android:layout_toRightOf="#+id/textView4" />
<!--thumbnail-->
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/thumbnail_image"
android:layout_marginTop="35dp"
android:gravity="center"
android:id="#+id/tile">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="50dp"
android:clickable="false"
android:layout_height="50dp"
android:src="#drawable/opened" />
</LinearLayout>
<TextView
android:id="#+id/crophead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignBottom="#+id/tile"
android:layout_alignLeft="#+id/title" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Certification"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/certification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/title"
android:text="Test"
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Audit Type"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/tile"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/audittype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/certification"
android:maxLines="2"
android:text="ES"
android:textColor="#343434"
android:textSize="17sp" />
<View
android:layout_width="fill_parent"
android:layout_height="3px"
android:layout_marginTop="200dp"
android:background="#21265b"
android:id="#+id/view" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/view"
android:layout_alignLeft="#+id/view"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="false" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_alignTop="#+id/textView6"
android:layout_alignRight="#+id/startdate" />
<TextView
android:id="#+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="30/05/1992"
android:textSize="17sp"
android:layout_alignTop="#+id/enddate"
android:layout_toRightOf="#+id/relativeLayout2"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="2/13/14"
android:textSize="17sp"
android:id="#+id/enddate"
android:layout_below="#+id/textView7"
android:layout_alignRight="#+id/textView7" />
<TextView
android:id="#+id/farm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/audittype"
android:maxLines="3"
android:layout_alignTop="#+id/title"
android:text="Tea Estate Nagarcoil Tamil Nadu, India "
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/crop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/farm"
android:layout_alignTop="#+id/crophead"
android:maxLines="2"
android:text="Wheat without its chaff and barn but not brown"
android:textColor="#343434"
android:textSize="17sp" />
<Button
android:id="#+id/upsync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/blue_thumb"
android:layout_below="#+id/enddate"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Show Results"
android:textColor="#android:color/white" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/upsync"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_below="#+id/enddate"
android:background="#drawable/blue_thumb"
android:text="Submit"
android:textColor="#android:color/white" />
</RelativeLayout>
Here is the click snippet of the list view:
listview.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
long audit_id;
try{
audit_id = (new CustomListAdapter(HomeList.this, c).getAuditID(position));
changeTileStatus(audit_id,"opened");
System.out.println("listClicked");
sendAuditAndIntent(audit_id);
}catch(Exception e)
{
System.out.println("ERROR # HOMELIST list onClick: "+e);
}
}
private void sendAuditAndIntent(long audit_id) { //sends audit id and api key
Intent intent = new Intent(HomeList.this,ChapterActivity.class );
Bundle extras= new Bundle();
extras.putString("audit_id",String.valueOf(audit_id));
extras.putString("api_key", api_key);
intent.putExtras(extras);
startActivity(intent);
}
private void changeTileStatus(long audit_id, String value) {
AuditTableManager tile= new AuditTableManager(HomeList.this);
tile.open();
tile.updateEntry(audit_id, value);
tile.close();
}
});
OnItemClickListener is not called if cells contain clickable Views. It is an Android feature. You can handle clicks by OnClickListener then - set it to your two buttons (not the listView itself).
In your adapter:
public View onCreateView(..., final int position){
...
convertView.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction1(position);
}
});
convertView.findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction2(position);
}
});
...
}
Try android:Focusable="false" and also android:clickable="false" in the custom row TextView

Categories

Resources