I am trying to access a button from a specific view. The same view is displayed 6 times. This is the code I am using.
public void testTimeConfig(){
onData(withDesc("description")).onChildView(withId(R.id.positive)).perform(click());
}
private static Matcher<Object> withDesc(String desc) {
return allOf(is(instanceOf(String.class)), is(desc));
}
When I run, I get an error:
Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.
Is this the best way to access a child view? If so, how?
EDIT
This is the code I am trying to use now.
onView(allOf((withContentDescription("description")), hasSibling(withContentDescription("SettingsLayout")), hasSibling(withId(R.id.positive)))).perform(click());
and
onView(allOf((withContentDescription("description")), hasSibling(withId(R.id.positive)))).perform(click());
With this Error:
No views in hierarchy found matching
The xml
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/setAGoalTitle"
android:layout_alignParentLeft="true"
class="com.xxx"
android:layout_marginTop="30dp"
android:id="#+id/timeGoalWidget"
app:goalLabel="#string/time_min_upper"
app:icon="#drawable/ic_icn_summary_time"
app:step="300"
app:valueFormat="time"
android:gravity="center_horizontal"
android:layout_marginBottom="60dp"
android:contentDescription="setAGoalTimeConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/timeGoalWidget"
class="com.xxx"
android:id="#+id/distanceGoalWidget"
app:goalLabel="#string/distance_upper"
app:icon="#drawable/ic_icn_summary_track"
app:step="0.25"
app:valueFormat="decimal_two"
android:gravity="center_horizontal"
android:contentDescription="setAGoalDistanceConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/timeGoalWidget"
android:layout_alignLeft="#id/timeGoalWidget"
class="com.xxx"
android:id="#+id/paceGoalWidget"
app:goalLabel="#string/pace_upper"
app:icon="#drawable/ic_icn_summary_pace"
app:valueFormat="time"
app:step="10"
android:gravity="center_horizontal"
android:layout_marginBottom="60dp"
android:contentDescription="setAGoalPaceConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/distanceGoalWidget"
android:layout_alignTop="#id/paceGoalWidget"
class="com.xxx"
android:id="#+id/speedGoalWidget"
app:goalLabel="#string/speed_upper"
app:icon="#drawable/ic_icn_summary_speed"
app:step="0.5"
app:valueFormat="decimal_two"
android:gravity="center_horizontal"
android:contentDescription="setAGoalSpeedConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/paceGoalWidget"
android:layout_alignLeft="#id/paceGoalWidget"
class="com.xxx"
android:id="#+id/inclineGoalWidget"
app:goalLabel="#string/incline_percent_upper"
app:icon="#drawable/ic_icn_summary_elevation"
app:step="0.5"
app:valueFormat="decimal_two"
android:gravity="center_horizontal"
android:contentDescription="setAGoalInclineConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/speedGoalWidget"
android:layout_alignTop="#id/inclineGoalWidget"
class="com.xxx"
android:id="#+id/caloriesGoalWidget"
app:goalLabel="#string/calories_upper"
app:icon="#drawable/ic_icn_summary_calories"
app:step="10"
app:valueFormat="decimal_zero"
android:gravity="center_horizontal"
android:contentDescription="setAGoalCaloriesConfigurator"/>
</RelativeLayout>
The view xml that is used 6 times.
<ImageButton
android:id="#+id/increaseGoalButton"
android:layout_height="#dimen/view_goal_setting_incrementor_button_height_width"
android:layout_width="#dimen/view_goal_setting_incrementor_button_height_width"
android:background="#drawable/button_goal_widget"
android:gravity="center"
android:src="#drawable/ic_plus"
android:textSize="#dimen/view_goal_setting_incrementor_button_text_size"
android:textColor="#color/goal_configuration_widget_button_text_color"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="1dp"
android:contentDescription="#string/increase"/>
<ImageButton
android:id="#+id/decreaseGoalButton"
android:layout_height="#dimen/view_goal_setting_incrementor_button_height_width"
android:layout_width="#dimen/view_goal_setting_incrementor_button_height_width"
android:background="#drawable/button_goal_widget"
android:gravity="center"
android:src="#drawable/ic_minus"
android:textSize="#dimen/view_goal_setting_incrementor_button_text_size"
android:layout_alignParentRight="true"
android:textColor="#color/goal_configuration_widget_button_text_color"
android:layout_below="#id/increaseGoalButton"
android:contentDescription="#string/decrease"/>
<LinearLayout
android:id="#+id/goalWidgetValueContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toLeftOf="#id/increaseGoalButton"
android:layout_centerVertical="true"
android:gravity="center_vertical|right"
android:layout_marginRight="#dimen/view_goal_setting_value_margin_right" >
<TextView
android:id="#+id/goalValueTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/goal_configuration_widget_value_text_color"
android:textSize="#dimen/view_goal_setting_value_text_size"
android:lineSpacingExtra="-10sp"
app:typeface="proxima_bold"
android:text="999:00"/>
<TextView
android:id="#+id/goalValueLabelTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textSize="#dimen/view_goal_setting_value_label_text_size"
android:textColor="#color/goal_configuration_widget_value_text_color"
android:includeFontPadding="false"
android:lineSpacingExtra="10sp"
android:text="#string/incline_percent_upper"/>
</LinearLayout>
It is the ImageView with id increaseGoalButton that I am trying to click.
Based on your last comment you should use onView() instead of onData().
I think you'll be able to click the button using hasSibling() - example
onView(allOf(withId(R.id.positive), hasSibling(withDesc(someString))))
.perform(click());
or examples without your custom matcher (sibling view has text):
onView(allOf(withId(R.id.positive), hasSibling(withText(someString))))
.perform(click());
or (sibling view has content description):
onView(allOf(withId(R.id.positive), hasSibling(withContentDescription(someString))))
.perform(click());
EDITED:
OK, I'd try these two variants:
onView(allOf(withId(R.id.increaseGoalButton), isDescendantOfA(withId(R.id.timeGoalWidget))))
.perform(click());
or
onView(allOf(withId(R.id.increaseGoalButton), withParent(withId(R.id.timeGoalWidget))))
.perform(click());
None of your content descriptions match the string "description" that's why it doesn't find anything.
Assuming the button id is R.id.positive, and the id is unique in the current activity view, you can simply use:
onView(withId(R.id.positive)).perform(click());
Related
I have a data-structure which is of type:
ArrayList<ArrayList<String>>;
...It contains a set of elements of a news feed; each element is itself a list of fields and each field is a tuple(key:value) where both key&value are of type String.
NOTE: the reason fields are stored in ArrayList is I don't always know how many the feed-parser will spurt out.
The view:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="#+id/news"
android:text="#string/news_and_events"
android:layout_row="6"
android:layout_column="4"
android:layout_columnSpan="3"
android:layout_rowSpan="3"
android:width="180dp"
android:height="245dp"
android:layout_marginBottom="10dp">
<!--FEED-->
<ListView
android:id="#android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</RelativeLayout>
The row-template I want to use is:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="#+id/picture"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription=""
/>
<!--STARTING WITH title-->
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/picture"
android:ellipsize="marquee"
android:singleLine="true"
android:text=""
android:textSize="20sp"
/>
<TextView
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
As you can see there are 3-fields: title, body, image (a news feed).
So I'm completely stumped as to what type of adapter I should use.
All the ones' I've looked at don't seem to match what I want to do; specifically because of the data-structure I'm using.
Perhaps I should use a cursor adapter?
If so, how would I map this into a Relational-database?!
I think you should try using a BaseAdapter, it's the most flexible adapter Android has(I think)...
By doing so, you can implement a custom Adapter, which goes thru the ArrayList(using 2 cycles for extracting) and then parsing it to the visual components you specified.
Since it's constructor receives the context, the view and the data, you'll have the ImageView and so, there.
Four views are using same xml. I want to show a linear layout for view 1 only.
I put android:visibility="gone" in xml. And then I am doing the following for view 1-
LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);
layone.setVisibility(View.VISIBLE);
But that doesn't set the visibility to visible.
Isn't it possible to show the view once its declared GONE in xml ?
I don't want to converse the logic by just doing,
layone.setVisibility(View.GONE);
in each of the three views except view 1.
Ideas or comments?
UPDATE:
My xml -
<TextView
android:id="#+id/layone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous Page"
android:textColor="#000000"
android:textSize="16dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:tag="PrevEntries"
android:id="#+id/laytwo"
android:layout_marginTop="10dp"
android:background="#layout/roundedtext"
android:visibility="gone" >
<TextView
android:id="#+id/laythree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Previous Page"
android:textColor="#000000"
android:textSize="18dp"
android:gravity="center"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/layone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous Page"
android:textColor="#000000"
android:textSize="16dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:visibility="gone" />
layone is a TextView.
You got your id wrong.
LinearLayout layone= (LinearLayout) view.findViewById(R.id.laytwo);// change id here
layone.setVisibility(View.VISIBLE);
should do the job.
or change like this to show the TextView:
TextView layone= (TextView) view.findViewById(R.id.layone);
layone.setVisibility(View.VISIBLE);
Done by having it like that:
view = inflater.inflate(R.layout.entry_detail, container, false);
TextView tp1= (TextView) view.findViewById(R.id.tp1);
LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);
tp1.setVisibility(View.VISIBLE);
layone.setVisibility(View.VISIBLE);
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/activity_register_header"
android:minHeight="50dp"
android:orientation="vertical"
android:visibility="gone" />
Try this piece of code..For me this code worked..
Kotlin Style way to do this more simple (example):
isVisible = false
Complete example:
if (some_data_array.details == null){
holder.view.some_data_array.isVisible = false}
put this attribute in your xml view for Gone
android:visibility="gone"
put this attribute in your xml view for Show
android:visibility="visible"
Example
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/futura_medium_bt"
android:text="•Unlock all graphics"
android:textAllCaps="true"
android:visibility="gone"
android:textColor="#color/black"
android:textSize="#dimen/_12ssp" />
I am using a Relative Layout(RL) to Hold a List View(lv) and a few bunch of other widgets like Text View(tv), Edit Text(et), then a few Buttons(btn) and finally one Progress Bar(pb).
Scenarios
1. When i add child Views to the Parent Container View viz. Relative Layout(rl), in the order: RL(Btn1->Btn2->tv1->tv2->LV->pb). Then we have no problem, i mean No Exception, No Problem.
2. But when i do the ordering change like RL(tv1->tv2->LV->Btn1->Btn2->pb). then i am getting a classcast Exception.
Note: the two buttons should be over the listview, as both of them are social website buttons, i mean Facebook and Twitter.
XML Code:
<RelativeLayout
android:id="#+id/rlfornews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:background="#drawable/newsbg"
android:orientation="vertical"
android:paddingBottom="5dip" >
<Button
android:id="#+id/btnbasetw"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="10dip"
android:background="#drawable/twitter_icon"
android:visibility="gone" />
<Button
android:id="#+id/btnbasefb"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_toLeftOf="#id/btnbasetw"
android:background="#drawable/facebook_icon"
android:visibility="gone" />
<TextView
android:id="#+id/tvnewscon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:background="#drawable/newstitle"
android:gravity="center_vertical"
android:paddingLeft="8dip"
android:shadowColor="#color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:text="#string/news"
android:textColor="#color/white" />
<TextView
android:id="#+id/tvfornews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvnewscon"
android:layout_marginTop="10dip"
android:gravity="center"
android:text="#string/no_data_found"
android:visibility="gone" />
<ListView
android:id="#+id/lvdashboardnews"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tvnewscon"
android:padding="4dip"
android:visibility="visible" >
</ListView>
<ProgressBar
android:id="#+id/pbfornews"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
Note: The Progress Bar might be below, but it is just to user information, that some data is loading. and when i get that data, i am making its Visibility to VIEW.GONE state, and the List View being already there !
My question is when i follow the First Scenario, even though i have a Progress Bar from the entire time, i am not getting a Class Cast Exception. But i am getting the exception, when i change to Scenario 2. So why i am i getting it?
I am not sure about these but may be the reason is you have used the android:layout_below = "#id/textview" instead of use these android:layout_below = "#+id/textview" all UI.
If you can do these UI using the LinearLayout.
I have a custom ListActivity in which i have a custom ListAdapter that inflates a layout for each item in the list. In eclipse, in the visual editor the layout looks like this
This is made by the following code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/largeFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:background="#color/mainBack"
android:orientation="vertical" >
<View
android:id="#+id/imageView1"
android:layout_width="5dp"
android:layout_height="fill_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_marginLeft="2dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/newtimeslot_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/imageView1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/black" />
<View
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_alignRight="#+id/newtimeslot_class"
android:layout_below="#+id/newtimeslot_class"
android:layout_toRightOf="#+id/imageView1"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/newtimeslot_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/newtimeslot_class"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#646464" />
<TextView
android:id="#+id/newtimeslot_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageView2"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#646464" />
<TextView
android:id="#+id/newtimeslot_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/newtimeslot_location"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#646464" />
</RelativeLayout>
</FrameLayout>
Unfortunately though, when i run this on an android device, the line to the left completely disappears. It instead looks like
I have just done the usual in terms on inflating it, and i only ever access the TextView objects. So i'm just wondering what could possibly be going on and if someone could help me out of this mess?
Cheers
Edit: The inflation code
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(R.layout.timeslotlayout_new, parent, false);
return view;
}
I suspect the reference #android:color/darker_gray to be the problem.
It might be that on some devices, this value does not exist ?!? (it may be under another name for instance)
Try setting the background attribute to a COLOR value (instead of an android color reference) like this #00000 which represents black (or choose another custom color like this #A9A9A9 for DarkGray ) :
android:background="#A9A9A9"
/OR/
Create an XML file for most basic colors like done HERE, in this manner you are sure that the colors will not change among devices, and most of all, that they will exist on all devices for your application.
So if you do so (see the link), you can create a color like this (the name of the XML file does not matter at all) :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Black">#000000</color>
<color name="DarkGray">#A9A9A9</color>
</resources>
And reference it in the following way :
android:background="#color/DarkGray"
Note :
No matter if this solved your issue or not, I strongly advise you to follow this manner to be on the safe side.
Maybe you're missing to set this:
android:layout_alignParentLeft="false"
to this:
android:layout_alignParentLeft="true"
And, by the way, android:orientation="vertical" doesn't apply to a relative layout. It applies only to LinearLayout.
And to the newtimeslot_time TextView change the
android:layout_toRightOf="#+id/imageView1"
to
android:layout_toRightOf="#id/imageView1"
Hope it helps!
Cheers!
I have a default ListView that i have added my custom views for the list items, but the buttons inside of these views are not clickable most of the time. I output a Log.v when the button receives a click event, but i have to tap the button almost a dozen times before it will register the click.
The other problem related tot his that i am having is that when the button is pressed i want an animation to happen revealing a menu sliding out from beneath it. At the moment i have tried several different methods like making a custom class for the views versus just using a layout inflater to get the relativeLayout object for the view, but nothing is working properly. I have even tried using listview.getAdapter().notifyDataSetChanged(); but that only has a pop-into-place for the extended view when i want an animation.
I have searched everywhere and it seems like the only possible solutions are to either rewrite my own custom listview or to use a linearlayout with a scrollview. The latter seems easier but i dont think it is nearly as optimized as the listview is.
Any suggestions would be greatly appreciated, if you need to see some code, please let me know...
Thanks!
UPDATE:
the getView() contains this:
Holder hold;
convertView = friends.get(position);
hold = new Holder();
hold.pos = position;
convertView.setTag(hold);
return convertView;
basically i pass an ArrayList<RelativeLayout>, at the moment, to the Adapter so that i dont have to create a new view each time and so that the animation will stay animated when i scroll down...
inside the OnCreate() for this activity i set that ArrayList<RelativeLayout> with this next code, but this is only temporary as i plan to use another method later, like an Async task or something so that this view contains some data...
RelativeLayout temp;
for(int i=0; i<30; i++){
temp = (RelativeLayout) inflater.inflate(R.layout.list_item, null);
final LinearLayout extraListItemInfo = (LinearLayout) temp.findViewById(R.id.extraListItemInfo);
Button infoBtn = (Button) temp.findViewById(R.id.infoBtn);
infoBtn.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Log.v("ListItem", "Button has been clicked... ");
extraListItemInfo .setVisibility(View.VISIBLE);
ExpandAnimation closeAnim = new ExpandAnimation(extraListItemInfo , animHeight);
closeAnim.setDuration(750);
closeAnim.setFillAfter(true);
if(extraListItemInfo .getTag() == null || !extraListItemInfo .getTag().equals("expanded")){
extraListItemInfo .getLayoutParams().height = 0;
friendInfoList.startAnimation(closeAnim.expand());
extraListItemInfo .setTag("expanded");
}else if(extraListItemInfo .getTag().equals("expanded")){
extraListItemInfo .startAnimation(closeAnim.collapse());
extraListItemInfo .setTag("closed");
}
//((BaseAdapter) listview.getAdapter()).notifyDataSetChanged(); i tried it here once but then left it
//as the only action inside the listview's onitemclick()
}
});
listItems.add(temp);
}
this is the list item that i am using:
<?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="wrap_content"
android:background="#color/darkgrey"
android:paddingBottom="5dp" >
<LinearLayout
android:id="#+id/extraListItemInfo "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listItemInfo"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-10dp"
android:background="#color/grey"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:id="#+id/RelativeLayout04"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height"
android:layout_marginTop="5dp" >
<ImageView
android:id="#+id/ImageView04"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView04"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout03"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height" >
<ImageView
android:id="#+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView03"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView02"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/imageView1"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_list_height">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView01"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/listItemInfo"
android:layout_width="wrap_content"
android:layout_height="95dp"
android:background="#drawable/friend_cell_background2x"
android:clickable="true" >
<RelativeLayout
android:id="#+id/leftLayout"
android:layout_width="90dp"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgCompany"
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:scaleType="centerInside"
android:src="#drawable/user2x" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="#drawable/online_indicator2s" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/leftLayout"
android:background="#android:color/transparent"
android:gravity="left|center"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView
android:id="#+id/lblCompanyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Name"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/lblReawrdDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Played Offer"
android:textColor="#color/white"
android:textSize="17dp" >
</TextView>
</LinearLayout>
<ImageView
android:id="#+id/imageView4"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:src="#drawable/facebook_btn2x" />
<Button
android:id="#+id/infoBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/imageView4"
android:background="#drawable/info_btn2x"
android:clickable="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="13dp"
android:layout_toLeftOf="#+id/infoBtn"
android:text="Follows 30+"
android:textColor="#color/white"
android:textSize="11dp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="75dp"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/textView2"
android:background="#drawable/fan_btn2x"
android:text="Fans 30+"
android:textColor="#color/white"
android:textSize="11dp" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/imageView4"
android:src="#drawable/google_btn2x" />
</RelativeLayout>
</RelativeLayout>
sorry for any layout problems that may make things difficult to read... but i hope this helps you guys to understand my problem... Thanks
UPDATE 2:
All of these answers have been helpful in some way, but i think the main issue that i must first fix is why the buttons do not receive click events until i have first scrolled away from that listItem, then back to it, then clicked the button again... If someone can help find a solution to THAT i think that everything else will be much easier to solve...
Thanks...
A screenshot as requested, but remember that this shot was taken on a samsung galaxy tab 10.1 and due to me using the same layout for this larger screen, it looks much different from what it does on the phone i usually test with (Motorola droid x that isnt rooted and cant take screenshots...)
Another Update:
I managed to get the clicking and animation working nicely by Extending ArrayAdapter instead of base adapter. Sadly i am still experiencing problems as only the bottom half of the list is clickable. The top half of the list still behaves as before with the very glitchy click events... Any ideas as to what is happening this time? Thanks...
Well this isn't really an answer, but after rewriting this a few times I managed to fix it so that it functions exactly the way I wanted.
This time I left all of the data separate from each view and had each list item be a custom class inheriting RelativeLayout and also implementing its own OnClickListener for its specific infoBtn.
My adapter now simply extends ArrayAdapter<> and overrides this getView() method:
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView != null && (convertView instanceof FriendListItem2))
((FriendListItem2) convertView).setFriendInfo(friends.get(position));
else
convertView = new FriendListItem2(getContext(), friends.get(position));
return convertView;
}
Finally, in the main activity for this page I simply set the ListView with an adapter that I passed the data to.
This is all much cleaner than I had before and I wish it hadn't taken several rewrites of the code to get it right. Hopefully someone can benefit from this, though I still have no clue why I was getting a problem before.
Thanks for all previous suggestions.
try using this property in the top level layout in which your child views are placed.
android:descendantFocusability="blocksDescendants"
Its a bit tricky but I would suggest that if the above line does not work, try toggling between the removing of focusable=true and focusable="false" from the buttons. It should work.
Cheers!
That is a complex layout to create for every row...
Anyway, when you use the new keyword you are creating a different scope. In short your onClickListener does not see the 30 different extraListItemInfo references you expect it to see.
Try something like this:
#Override
public void onClick(View v) {
LinearLayout extraListItemInfo = v.getParent();
...
add android:onClick="onClick" to your button xml, it'll make it call the onClick() method
I had the same problem. Try taking the "android:clicable="true" " from the Relative Layout. When you do that the activity expects you to do make setOnClickListener to that RelativeLayout . It worked for me
you can fire click event on button from getView() method of ListViewAdapter Class.
See this question
Android : How to set onClick event for Button in List item of ListView.