Icon doesn't load - android

Hi my icons don't load and i don't know why. They should appear in the navigation. Im very new and don't find good new resources to learn.
Everything is old. Some links would help thank u.

The GetView needs to set the image on the ImageButton in the layout. Notice that you aren't even using the items in your adapter? Instead of using a list of ImageButton why not accept the drawables, and then set the image of each ImageButton from the items? See an updated version of GetView (below) which should get you a working example of setting the image on the ImageButton in each of your buttons.
public override View GetView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null){
v = LayoutInflater.From(context).Inflate(Resource.Layout.MenuButtonLayout, parent, false);
}
var imageButton = v.FindViewById<ImageButton>(Resource.Id.myButton);
imageButton.SetImageResource(Resource.Drawable.Noten);
return v;
}

Related

Add listView header between list

This is my listView
I want to add a February header on top of 2016-02-02 and January in 2016-01-31. Is it possible?
Yes, you can do this by returning a different view in your getView() method in your adapter class. In your master list, that you pass to your adapter, you can add a divider item, a String or however you are holding all this data, I assume a custom class, that you know is meant to show a Month title. You can do a quick check in your getView() method and return a different view that displays the month..
In your getView() method, you can do this...
#Override
public View getView(final int position, View convertView, ViewGroup parent){
LayoutInflater mInflator = LayoutInflater.from(getContext());
View customView = mInflator.inflate(R.layout.times_layout, parent, false);
Time temp = getItem(position);
//Check to see if the time is supposed to be a header
//This is where you check to see if it meant to be a section header
if(temp.getDate.equals("HEADER")){
//Header, return section view instead of normal view
View sectionHeader = mInflator.inflate(R.layout.layout_list_divider, parent, false);
TextView txt_Section = (TextView) sectionHeader.findViewById(R.id.txt_Header);
sectionHeader.setClickable(false);
return sectionHeader;
}
//Normal View... do what you would do normally
return customView;
}
I hope this helps! Let me know.. it worked for me
In android It's called ExpandableListView
You can try this tutorial:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
It also has a sample to download.

How can I change the Background Resource from the first ListView visible Item?

I'm Noob at Java Android.
I searched more about my question and I found that I can use
listView.getFirstVisiblePosition();
To get my first visible position. How can I implement a new Background Resource only to my first visible position?
I tried to do that by far.
View get = lv.getFirstVisiblePosition()
get.setBackgroundResource(R.drawable.newconversation);
Thanks.
There is a method in your adapter which controls your list items views
#Override
public View getView(int position, View convertView, ViewGroup parent) {
You can just use this condition :
if(position == 0)
//set your background
After convertView has been inflated
getFirstVisiblePosition() returns an Integer position. You want to get the view at that position.
Try
View view = list.getChildAt(list.getFirstVisiblePosition());
Then set your background on the view.

Android: ListView changing wrong row layout visibility

I have listview with hundred of items. Every item had a couple of LinearLayouts but ONE of them is Visibility.GONE! Every item has textviews and an image. On Image Click i want to set the LinearLayout with visibility.Gone to View.VISIBLE. It works fine until you scroll down the listview, then every 4th item has the same layout set to VISIBLE but i only need the Clicked one! Here is the getView method:
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ImageView imgForClick;
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.custom_row, null);
final LinearLayout hiddenLayout = (LinearLayout)vi.findViewById(R.id.hiddenLayout);
imgForClick = (ImageView)vi.findViewById(R.id.imageView3);
imgForClick.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
hiddenLayout.setVisibility(View.VISIBLE);
}
});
return vi;
}
That's because you are recycling the views, so the layout gets changed on a click and then that layout is used in your other rows to save memory.
You need to remember the state of each of the rows to know whether or not the layout should be visible or not
Have something like this:
public View getView(final int position, View convertView, ViewGroup parent) {
...
if (shouldBeVisible.get(position)) {
hiddenLayout.setVisibility(View.VISIBLE);
} else {
hiddenLayout.setVisibility(View.GONE);
}
That way the layout will always be set one way or another.
shouldBeVisible is a List of something that lets you know which rows should have that layout visible or not.
EDIT--
An alternative is to remove view recycling, however this will dramatically hurt performance and should NOT be done, but I'm just explaining to list all your options.
You would remove the line
if (convertView == null)
Making Android always inflate a new view, instead of using the recycled one when possible.

GridView with customs view

I don't know if it is possible, but actually I wouldn't see why not.
Can we do a grid view not just with ImageView but with a custom view.
I am trying to make a grid view of a view composed of an ImageView and a TextView.
I know that everything happens in my Adapter getView's function but I can't figure out how to do it.
public View getView(int position, View convertView, ViewGroup parent) {
View cases = findViewById(R.id.fileUnitLayout);
if (convertView == null) {
convertView = new View(mContext);
} else {
cases = convertView;
}
return cases;
}
My view has an id of R.id.fileUnitLayout. Let's say my inner TextView has an id of A and my inner ImageView has an id of B. How can I fill them ?
Thank you,
You should not need to override getView to accomplish this, necessarily. GridView is an AdapterView so you can provide an adapter that will display what you want via setAdapter
You could, for example, use SimpleAdapter to provide an xml file that is used for each grid view item.

Android: How do I make the background color of a ListView show up behind the selection?

I have a ListView powered by a custom adapter that dynamically changes the background color of each row based on its contents. The getView looks like this:
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
Power power = powers.get(position);
if(row == null)
{
row = getLayoutInflater().inflate(android.R.layout.simple_list_item_2, parent, false);
}
TextView text1 = (TextView)row.findViewById(android.R.id.text1);
TextView text2 = (TextView)row.findViewById(android.R.id.text2);
text1.setText(power.name);
text2.setText(power.getAttackLine());
row.setBackgroundColor(0xFF0000FF);
return row;
}
All that works peachy, except that whenever I select an item from the list, the standard red/orange highlight only shows up behind the row, only visible for a few pixels on each side of it. Is there a way to get the selection to show up on top of the background?
Try android:drawSelectorOnTop="true" in the <ListView> element in your layout.
I think the problem is that you're using simple_list_item_2, which has some padding/margin built into it. I recommend making your own version of simple_list_item_2, wherein you have both the height and the width set to fill_parent. You can see the latest simple_list_item_2 here.

Categories

Resources