I created a custom listview for installed apps. The listview contains icon and text. Now my problem is how to get/retrieve the BitmapDrawable icon from the customised listview when onListItemClick?
The icons in the custom listview is from:
static ArrayList<BitmapDrawable> Iconlist= new ArrayList<BitmapDrawable>();.
Inside onListItemClick I used:
SelectedIcon=(BitmapDrawable) Iconlist.get(position);
to get the icon, but its not working.
Please help me.
As #Rakesh Bhalani says, you should use the view returned by onListItemClick as argument, casting the view for an ImageView:
ImageView imageView = (ImageView)view.findViewById(id_of_your_icon);
then extract the drawable from the ImageView, casting as BitmapDrawable:
BitmapDrawable drawable = (BitmapDrawable)imageView.getDrawable();
In onItemClick listener of ListView you will get clicked 'view' as an argument, you should use view.findViewById(id_of_your_icon) to get the icon.
Related
I want to set the opacity of each and every Listview row using android:alpha. I tried doing so but the row doesn't get the transparent background. I have a colorful background of the layout and I want a glass or transparent type of row of the ListView. How can I do it?. I don;t want to use any adapters for this. So please suggest some simple methods.
View backgroundimage = findViewById(R.id.background);
Drawable background = backgroundimage.getBackground();
background.setAlpha(80);
If you are set opacity of listView us below Code
android:background="#80ColorCode"
i'am using a list in my main activity
and i don't want to use android list , i want to create my own list ,already i created my custom Adapter that enables me to use images and text in any row of list but i want to disable the divider of the list and the hover mode
it's mean that i don't want to have something like this pic
it is not my project screenshot
thanks in advance,
related with Avoid ImageView hover state inside Listview if List Item is pressed
you can use :
set empty background
android:cacheColorHint="#android:color/transparent"
or
android:cacheColorHint = "#00000000"
to remove divider between items in the list use :
myListview.setDivider(null);
or XML:
android:divider="#null"
android:dividerHeight="0dp"
in your adapter, override the method isEnabled(int position) and have it return false for this item.
Since you already have your own CustomListAdapter, do the following in your onCreate() method:
ListView list=(ListView)findViewById(R.id.list); //or whatever the id of your listview is
// Getting adapter by passing xml data ArrayList
YourCustomAdapter adapter = new YourCustomAdapter(this, listDataToBeDisplayed);
list.setAdapter(adapter);
Try code below to disable the highlight, you may change the text color as well
ListView.setSelector(new ColorDrawable(Color.TRANSPARENT));
How to set group indicator for ExpandableList View dynamically ?
I had group_indicator.xml in drawable folder.
But no idea of how to set it. Can anyone help please...
First set android:groupIndicator="#android:color/transparent" to your expandable list view in xml. Then you can set any indicator that you want to set. Suppose you have an image named "pin" in your drawable folder, then you need write following lines.
ExpandableListView explist;
Drawable d = getResources().getDrawable(R.drawable.pin);
explist.setGroupIndicator(d);
Thanks...
Suppose you have created ExpandableListView through code:
ExpandableListView ev = new ExpandableListView(this);
ev.setGroupIndicator(getResources().getDrawable(R.drawable.group_indicator));
I am working on an android application. I have created a listview by using
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arrayname));
getListView().setTextFilterEnabled(true);
Now i want to change the selected item's color. I could change the background of the selected item by placing
listviewobject.getChildAt(position).setBackgroundColor(Color.BLACK);
in onListItemClick()
this code is changing the background color but if I select any other list item then also the previously clicked list item's color is red.So I change the previously clicked listitem's color by
l.getChildAt(prevpos).setBackgroundColor(Color.BLACK);
now the problem is if i change the background of previously clicked listitems color to black.Then i can't see the text on that particular listitem.I i click again then only i can see the text on that item.So its look weired.please help me friends
After going through lots of posts and blogs i found this solution it works for me...
declare row variable global
public View row;
your_list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v,
int position, long id) {
if (row != null) {
row.setBackgroundResource(R.color.orange);
}
row = v;
v.setBackgroundResource(R.color.transparent_green);
)};
Well using this in the properties of your list view mught help:
android:listSelector="#drawable/list_selector"
It will automatically set the selected drawable as background of the selected item. Hope this works for you and drawable may be your own choice's color.
Explanation: Add an image strip to your drawables folder/s and set that image in listSelector attribute of the your list view. Now you will navigate through your list view, the list view's background will be of the color of the image strip you set instead of android's native color. Hope you get it now...:-)
I this This happening because you have put text color as black and your setting the background color also black that's why you can't see the difference. for setting the background color you can use the following line.
view.setBackgroundColor(Color.YELLOW);
use different color then text color.
By default the background is black. If you have customized your listview then when you scroll it would turn black. So when you define your list view set background cache color to the color you need as below:
yourlistView.setCacheColorHint(Color.WHITE);
What you can do is instead of using .setBackgroundColor() with a Color value, create a Color State List and assign it with .setBackgroundResource(). That way, you can define the various states that your list item can become, depending on the item's current state.
I wanna make a Gallery, with a picture in the background and a textfield with invisible background... So I can see the text and the Image behind.
I already made the Gallery but i cant figure out how to put text in the foreground.
You create a custom adapter to use for your gallery view, see Hello Gallery tutorial
In the method getView() you have two different ways to achieve the same result:
A. Make an ImageView and a TextView and set the image and text:
ImageView iv = new ImageView(context); //and so on, remember to set the LayoutParams etc to fit your design.
Make a RelativeLayout and add the ImageView and TextView to it
Return the RelativeLayout.
B. Declare a layout in xml, with a RelativeLayout containing a TextView and an ImageView
In getView, inflate this layout, and using
inflatedLayout.findViewById(R.id.myTextView); //and so on
set the text and image and return the layout.