Android: QuickContactBadge in the ListView - android

First the scenario:
I have a list where each item has a photo of a contact and some text. I would like to click on the image and bring up the QuickContactBadge. Badge is defined by the following XML snippet
<QuickContactBadge android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/badge"
android:layout_alignParentBottom="true"></QuickContactBadge>
What I tried and failed:
Define one reusable badge and reuse it for all cases. Both list and badge are placed into RelativeLayout
Have one badge defined per each list item. The item uses RelativeLayout
What do I see:
Basically nothing. The code gets valid badge instance and then I apply the following logic
contactPhoto.setOnClickListener(new OnClickListener() {
#Override
public void onClick(final View v) {
Log.d(TAG, "Image click");
if (badge != null) {
badge.assignContactFromEmail("johndoe#gmail.com", true);
badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
badge.bringToFront();
}
}
});
As I click I can step through the code in onClick handler yet the badge never comes up
The questions:
Does QuickContactBadge have any placement logic? When I click on the image do I need to calculate badge position and readjust or is it built-in?
Is it possible to achieve what I describe above (badge for images displayed in the list) and what I'm doing wrong (or missing)

Abort! Abort!
Basically I totally misunderstood what the badge is and how to use it. What I was trying to do is to detect click on image and call the badge. This is fundamentally wrong since all I needed to do was to simply use QuickContactBadge INSTEAD of ImageView in my code. After I replaced images with badges in the item XML magic was automatically there.
Said that - it is possible to pop the badge using the code, refer to this article on how to do it

Related

Changing background colour for the Selected Tab

This is my Screen layout, and i want to do this, when I clicked on Popular tab, then Popular block should turns Blue.
Same for the Price, Time and Duration tab.
I've tried to do with Linear Layout but it doesn't.
i have taken it in Text View, and the vertical and Horizontal Lines are used using View tag and I have not use TabLayout, just to make it simple I just used TextView With Background.
Please suggest me a proper solution with code if you can.
Any help would be Appreciated.
In your xml file add following line in your TabLayout,
app:tabBackground="#0000FA"
by this you can chage color of selected tab.
If you have used TextView then just simply create or add this method to you java file & call it from each textviews onclick event by passing the textview to it.
public void changeTabColor(TextView tvSelected){
tv1.setBackgroundColor(Color.White);
tv2.setBackgroundColor(Color.White);
tv3.setBackgroundColor(Color.White);
tvSelected.setBackgroundColor(Color.Blue);
}
try this :
public void onClick(View v) {
switch (v.getId()) {
case R.id.popular_tab:
ResetTabColor();
popular_tab.setBackgroundColor(Color.blue);
case //Do the rest with other tab
}
}
private void ResetTabColor(){
popular_tab.setBackgroundColor(Color.TRANSPARENT); // or white color
time_tab.setBackgroundColor(Color.TRANSPARENT);
duration_tab.setBackgroundColor(Color.TRANSPARENT);
price_tab.setBackgroundColor(Color.TRANSPARENT);

Android Placing Text (bar) at bottom of Application

I want to be able to display text (a bar if you will) at the bottom of my application dynamically to indicate if the the application is online or not (an endless issue for users currently). I don't need for this to have any action, but I do need it to be able to control it displaying or not based on them toggling between online and offline mode. So the split action bar is not what I am looking for.
Not enough reputation points to post an example. Doh. Here is the link:
Ugly example, look at bottom
Something simple is fine - I am good with XML based or dynamic (though I will also need to hide and show it dynamically).
Thanks!
Dynamic solution. Define your method that the activity will use to hide / display your bottom TextView (text bar?).
In your XML:
<TextView
android:id="#+id/text_bar"
...
...
android:visibility="gone"/>
In your activity:
public MyActivity extends Activity{
private TextView mTextBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_xml);
...
...
mTextBar = (TextView) findViewById(R.id.text_bar);
}
public void updateVisibility(boolean visible){
int visibility = (visible) ? View.VISIBLE: View.GONE;
mTextBar.setVisibility(visibility);
}
}
Initially, the TextView (your text bar) has it's visibiity set to gone. Dynamically, when you want to show it call the updateVisibility(true) method to show it, and updateVisibility(false) to hide it.
Since I'm not sure how you are handling the check for the network status (in queries, in the onCreate, etc). I don't know what you intended to do for the TextView. If you need advice on how to position the TextView on the bottom of the screen I can provide example code for that as well.

setImageResource() will not update my ImageView size/content directly

I have a row in a listview activity where an image should be changed when the row is selected. The new image is identical but larger (double size) than the original image. It is supposed to be reduced when it is deselected (Selection is implemented using my internal selection, not the android keyboard selection kind) again.
Problem is when (selected) I change the picture (at the time of bind) of my ImageView () using setImageResource() it does not update to the new larger version in my List row on the first click. Second execution of bind works fine. The same applies for the old item being deselected. The change to a smaller icon does not get in effect until a second click. The problem repeats itself each time I select another row than the currently selected and starts working correctly again on the second click.
I have stepped through code and seen that I pass the right id to the ImageView and this is prooved by the fact that another View showing a yellow border on the same row is changed to visible/hidden when selected/deselected.
To me it feels like the setImageResource() does not refresh the view immediately, but using invalidate() on the view or the row has no effect at all.
Is this a bug (how to work around) or do I do something wrong?
Code: (from my holder class using the holder pattern - executed by the adapter bind method)
#Override
public void refreshFromCursor(final Context context, final Cursor cursor) {
...
boolean selected = adapter.getSelectedPosition()==cursor.getPosition();
if (selected){
selectedIndicator.setVisibility(View.VISIBLE); // Show a "selected" yellow border indicator to the left
} else {
selectedIndicator.setVisibility(View.GONE); // Hide a "selected" yellow border indicator to the left
}
...
if (selected) completionResId = R.drawable.folder_selected;
else completionResId = R.drawable.folder;
...
statusIcon.setImageResource(completionResId); // !!!!! This is where I set the image that does not refresh/resize
...
}
Also tested exchanging the
statusIcon.setImageResource(completionResId);
with
statusIcon.setImageDrawable(context.getResources().getDrawable(completionResId));
but nothing changes in the problematic behaviour
In my opinion it is about the way you have implemented,
if you provide us the full code of refreshFromCursor(...) function we can have better understanding of what you did.
I found a hack. just make your drawable bigger
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="500dp"
android:height="500dp"
android:viewportWidth="139"
android:viewportHeight="139">
<path
android:fillColor="#000000"
android:pathData="M117.037,61.441L36.333,14.846c..." />
</vector>
here I set the drawable to be drawn on a 500dp canvas (instead of a 139dp one that was there originally) and it did the trick. no more weird tiny icons that later increase in size.

List item click triggering child view's selector

I have an ImageView in my layout for the individual items of a list.
The ImageView's src is an XML file in the drawable folder that defines which images to use during the various states of pressing an item.
However, I've noticed when you click the list row (and not the ImageView itself) the selector assigned to the ImageView is activated. It doesn't actually hit the ImageView's onClick code, but the image toggles as if it has been clicked.
This is actually a desirable effect in some cases, but in this specific case it is not. Is there a way I can stop this from happening?
set android:duplicateParentState in child to true
I think you should read Cyril Mottier's blog. He has a post about this here.
In a word, you have to extends your Child views to Override the method setPressed(boolean) like this:
#Override
public void setPressed(boolean pressed) {
if (pressed && getParent() instanceof View && ((View) getParent()).isPressed()) {
return;
}
super.setPressed(pressed);
}

Making custom android views "tappable" with a feedback highlight

I'm using a custom view expanded from a XML layout in a horizontal scroll view as a sort of horizontal image list but I'm not sure how to get them to appear clickable/tappable (ie they highlight when tapped) or how to capture these events. I think I've tried setOnClickHandler without it working. I'm also trying to get a simple TextView to do the same. I've also tried setting android:clickable="true" but that hasn't helped either. Any ideas?
To take care of the visual feedback use an xml Selector, and set it as the View's background.
To handle click events use
mView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//your code here
}
});

Categories

Resources