android autocomplettextview Resource not found - Resource is not a drawable - android

This issue is driving me crazy....
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f0100ab a=3}
at android.content.res.Resources.loadDrawable(Resources.java:2816)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.(View.java:3460)
at android.widget.TextView.(TextView.java:791)
at android.widget.EditText.(EditText.java:76)
at android.widget.AutoCompleteTextView.(AutoCompleteTextView.java:137)
at android.widget.AutoCompleteTextView.(AutoCompleteTextView.java:133)
my xml is :
<AutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="38dp"
android:id="#+id/idautoCompleteProfTextView"
android:background="#drawable/edittext" <---**drawable**...
android:layout_marginLeft="30dp"
android:layout_marginTop="0dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="2dp"
android:textAlignment="center"
android:hint="#string/hint_signin_professional"
android:layout_below="#+id/btnAcceptSigninProf"
android:textColor="#000000"
android:dropDownVerticalOffset="5dp"
android:dropDownWidth="wrap_content"
android:inputType="textAutoComplete|textAutoCorrect"
android:popupBackground="#color/wallet_highlighted_text_holo_dark"/>
edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<corners android:radius="0dp"/>
<stroke android:width="2dip"
android:color="#ffffff" />
</shape>
Im inflating it as a fragment.
public class SigninProfessionalFragment extends Fragment {
public SigninProfessionalFragment(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_signin_professional, container, false);
...
I have not code-behind regarding the autocomplete because I just want to load it in my device and check layout,etc...

The problem should be in your theme, but not the code you posted.

Related

android how to select only one of button in adapter recycle view at view holder?

How to select the only 1 button out of 3 button? I manage to set/unset the background color on selected button for currently. But not able to select the only one selected button.
Example btn1, btn2, btn3.
When I selected btn1, the btn1 background was change color, and btn2 and btn3 not affected. After that when I selected the btn2 again, the btn1 background color was unset and the btn2 background was change color. So at this time the btn2 is selected and btn1 and btn3 not selected.
Below is my sample code:
public class ViewHolder extends RecyclerView.ViewHolder {
Button mButton;
public ViewHolder(View v) {
super(v);
parentActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
mButton= itemView.findViewById(R.id.mButton);
}
});
}
}
holder.mButton.setOnClickListener(new DebouncedOnClickListener(500) {
#Override
public void onDebouncedClick(View v) {
if(!holder.mButton.isSelected()){
holder.mButton.setSelected(true);
setSelectedButton(holder);
}
else{
holder.mButton.setSelected(false);
setSelectedButton(holder);
}
}
});
private void setSelectedButton(ViewHolder holder){
if(holder.mButton.isSelected()){
holder.mButton.setBackgroundColor(parentActivity.getResources().getColor(R.color.unread_notification));
}
else{
holder.mButton.setBackgroundColor(parentActivity.getResources().getColor(R.color.white));
}
}
What you need is to implement selection into your RecyclerView. After some searching, I found that this website might be useful for you
https://medium.com/#maydin/multi-and-single-selection-in-recyclerview-d29587a7dee2
I suggest you to use CheckBox instead of buttons like this -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/background"
android:orientation="horizontal">
<RadioButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_background"
android:button="#null"
android:gravity="center"
android:text="Button 1"
android:textColor="#fff"
android:checked="true"
android:textStyle="bold" />
<RadioButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_background"
android:button="#null"
android:gravity="center"
android:text="Button 2"
android:textColor="#fff"
android:textStyle="bold" />
<RadioButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_background"
android:button="#null"
android:gravity="center"
android:text="Button 3"
android:textColor="#fff"
android:textStyle="bold" />
</RadioGroup>
And for the Button background -
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<shape android:shape="rectangle" >
<corners android:radius="50dp"/>
<solid android:color="#c7c7c7"/>
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle" >
<corners android:radius="50dp"/>
<gradient android:startColor="#79ccff"
android:endColor="#7900ca"/>
</shape>
</item>
</selector>
And for the background -
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#c7c7c7" />
</shape>

id within drawable within layout

Edit: My question is different because the answer referenced is not trying to access and modify the drawable (which is what my question is about), but it is just replacing the drawable.
I'm trying to change the color of a shape within a drawable within a layout within a button.
My question is: How do I access the id for the shape element programmatically?
Here is the drawable that contains the shape within a selector (It is called 'ic_mf_account_icon.xml'):
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/accountShape">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/btn_bg_normal" />
<corners android:radius="#dimen/programmatic_btn_corner_radius" />
</shape>
</item>
<item android:right="10dp" android:left="10dp" android:top="10dp" android:bottom="10dp" android:drawable="#drawable/ic_server"/>
</layer-list>
</item>
</selector>
Here is the layout that contains the drawable I just listed (The drawable is referenced in the Button at the top):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/FilesListItem" >
<FrameLayout style="#style/FilesListContent" >
<Button
android:id="#+id/icon"
android:layout_width="36dip"
android:layout_height="36dip"
android:background="#drawable/ic_mf_account_icon" />
<include layout="#layout/files_list_item_overlay" />
</FrameLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingLeft="10dip"
android:singleLine="true" />
</LinearLayout>
<ImageButton
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:background="#null"
android:padding="#dimen/info_icon_padding"
android:src="#drawable/ic_info_grey_normal" />
</LinearLayout>
Here is where I'm trying to access the drawable. I can access the initial layout, but when I try to stem from there and access the drawable I get a null reference -- To note, This is within a fragments 'onCreateView(...)' function if that matters:
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_account_list, container, false);
FindView find = FindView.inView(view);
// AbsListView absListView = find.absList(android.R.id.list);
AbsListView absListView = view.findViewById(android.R.id.list);
absListView.setAdapter(arrayAdapter = new BaseListAdapter<Account>(getActivity(), accounts) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.fragment_account_list_item, parent, false);
View layoutView = convertView.findViewById(R.id.icon);
View drawableView = layoutView.findViewById(R.id.accountShape);
Drawable drawableBackground = drawableView.getBackground();
// From here I will endeavor to modify the drawables shape background.
Here is the code within the code just mentioned where I am trying to access the drawable from within the layout:
View layoutView = convertView.findViewById(R.id.icon);
View drawableView = layoutView.findViewById(R.id.accountShape);
Drawable drawableBackground = drawableView.getBackground();

How to make TextInputLayout NOT fill the background when error gets set?

I am getting the following. When the error is set, I don't want the box to be filled in red. I am new to using TextInputLayout. How do I fix this?
I have the following
<android.support.design.widget.TextInputLayout
android:id="#+id/til_confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/textBoxBottomGap"
android:layout_marginLeft="#dimen/leftRightMargin"
android:layout_marginRight="#dimen/leftRightMargin"
app:hintEnabled="false">
<EditText
android:id="#+id/confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edittext"
android:hint="Confirm Password"
android:inputType="textPassword"
android:maxLines="1"
android:paddingBottom="5dp"
android:paddingLeft="#dimen/padding"
android:paddingRight="#dimen/padding"
android:paddingTop="5dp"
android:ems="10"
android:textColor="#999999"
/>
</android.support.design.widget.TextInputLayout>
#drawable/rounded_edittext is referencing the following.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="15dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"/>
<stroke android:width="1dip" android:color="#999999" />
</shape>
I have the following in Activity:
if (!newPlainPssd.equals(confirmPlainPssd)) {
etConfirmPassword.requestFocus(); //references editText
tilConfirmPassword.setError("Passwords don't match"); //references TextInputLayout
return;
}
Try this
if (!newPlainPssd.equals(confirmPlainPssd)) {
etConfirmPassword.requestFocus(); //references editText
tilConfirmPassword.setError("Passwords don't match"); //references TextInputLayout
text.setError("Nilesh");
editText.setBackgroundColor(Color.TRANSPARENT);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
editText.setBackgroundResource(R.drawable.rounded_edittext);
}
}, 50);
return;
}
the soliton is change
<solid android:color="#FFFFFF"/>
to
<solid android:color="#color/transparent"/>

How to draw border for circular image view?

I am using drawable as image background for giving border but its not working as required (circle is not perfect).
Recycler view item layout
<data>
<variable
name="news"
type="com.android.mvvm.model.NewsItem" />
<variable
name="clickListener"
type="com.android.common.util.RecyclerViewOnItemClickHandler"></variable>
</data>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circular_image_selected"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="#{clickListener.onClick}"
android:src="#{news.thumb}" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circular_image_unselected"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="#{clickListener.onClick}"
android:src="#{news.thumb}"
android:visibility="gone" />
</FrameLayout>
Adapter's onBindViewHolder method where i am setting background to the image view on item selected
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof RecyclerViewHolder) {
NewsItem item = list.get(position);
RecyclerViewHolder newsViewHolder = (RecyclerViewHolder) holder;
if (item.isSelected) {
CircleImageView img = (CircleImageView) newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected);
newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected).setVisibility(View.VISIBLE);
img.setBackground(context.getResources().getDrawable(R.drawable.selected_img_bg));
} else {
CircleImageView img = (CircleImageView) newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_selected);
img.setColorFilter(Color.argb(150, 155, 155, 155), PorterDuff.Mode.SRC_ATOP);
newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected).setVisibility(View.INVISIBLE);
}
newsViewHolder.getBinding().setVariable(BR.clickListener,
new RecyclerViewOnItemClickHandler<>(item, position, listener));
newsViewHolder.getBinding().setVariable(BR.news, item);
newsViewHolder.getBinding().executePendingBindings();
}
}
Drawable for image background
<?xml version="1.0" encoding="utf-8"?><shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke android:color="#android:color/holo_red_dark" android:width="3dp"/>
<size
android:width="100dp"
android:height="100dp"/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:thickness="7.8dp"
android:innerRadius="0dp"
>
<solid
android:color="#F00"
/>
<stroke
android:width="1dip"
android:color="#FFF" />
use this as background to you image... increase thickness accordingly.. or if this doesn't work retain the previous background xml and add android:padding around 10 to 15 dp in your imageview
i solve this by placing imageview into relativelayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="5dp"
android:padding="2dp"
android:background="#drawable/imageborder"
android:src="#drawable/placeholder"
android:id="#+id/notificator_image"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke android:width="2dp"
android:color="#cc195d" />
</shape>

How to add badge to list

I want to add badge notification to my arraylist.But I couldn't find a tutorial for this.This is my list code:
public void chatList() {
conversationsAdapter=new ArrayAdapter<JsonObject>(this,0) {
#Override
public View getView(int c_position,View c_convertView,ViewGroup c_parent) {
if (c_convertView == null) {
c_convertView=getLayoutInflater().inflate(R.layout.random_bars,null);
}
JsonObject user=getItem(c_position);
String name=user.get("name").getAsString();
String image_url="http://domain.com/profile/thumb/"+user.get("photo").getAsString();
TextView nameView=(TextView)c_convertView.findViewById(R.id.tweet);
nameView.setText(name);
ImageView imageView=(ImageView)c_convertView.findViewById(R.id.image);
Ion.with(imageView)
.placeholder(R.drawable.twitter)
.load(image_url);
return c_convertView;
}
};
ListView conversationsListView = (ListView)findViewById(R.id.conversationList);
conversationsListView.setAdapter(conversationsAdapter);
conversationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startChat(conversationsAdapter.getItem(position));
}
});
}
My list:
I want to add badge to this list.How can I do this ?
Ps:I found a library https://github.com/jgilfelt/android-viewbadger but I don't want to use it.
Inflate the layout in custom listview which extends base adapter instead of array adapter. Add following layout into the custom list item layout.
drawer_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/list_selector">
<ImageView
android:id="#+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="#string/desc_list_item_icon"
android:src="#drawable/ic_home"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/icon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/list_item_title"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/counter_bg"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:textColor="#color/counter_text_color"/>
</RelativeLayout>
Use below drawable for background textview counter and set notification count value in textview
counter_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- view background color -->
<solid android:color="#color/counter_text_bg" >
</solid>
<!-- If you want to add some padding -->
<padding
android:right="3dp"
android:left="3dp" >
</padding>
<!-- Here is the corner radius -->
<corners android:radius="2dp" >
</corners>
</shape>

Categories

Resources