footer for custom dialog with a android default theme - android

I want to create context menu as follows , i am sure this is not traditional the context menu , its a kind of alert dialog which is being customized.
I tried following code but it adds the footer end of the ListView not to the dialog / context menu reference thread is ContextMenu with footer view (to add checkbox for 'make default' option)
dialog2.getListView().addFooterView(new CheckBox(this))
I have gone through the followig tutorial which has custom context menu , is it possible
to use this code to set a footer
http://www.tanisoft.net/search/label/Tutorial
I want following features , preciously the checkbox in the footer
EDIT
I reached to this part now there are only two issues
1) Dialog Title Icon
2) Dialog Bottom Blue Color ( which is a default
color of android )
and i don;t know how to achieve above two task
Here is my code to create dialog
contactDlg = new Dialog(this);
contactDlg.requestWindowFeature( Window.FEATURE_LEFT_ICON );
contactDlg.setTitle(contactStore.getContactName());
contactDlg.setContentView(R.layout.contact_dialog);
contactDlg.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.bottom_bar);
contactAdapter = new ContactAdapter(this,contactStore.getContactNumber());
modeList = (ListView) contactDlg.findViewById(R.id.contactDlgList);
modeList.setBackgroundResource(android.R.color.white);
modeList.setCacheColorHint(Color.WHITE);
modeList.setAdapter(contactAdapter);
contactDlg.show();

No need to do any thing special for this.This can be achieved easily by creating your own layout containg the list shown in this pic and the footer view in the dialog itself with thye color and style you want.Then just make the property of the dialog named "windowFrame" to be null by < item name="android:windowFrame">#null< / item>Also you can make a separate "theme.xml" in the "values" folder and define this and similar kinda properties in that file.In code, when you instantiate the dialog object, set this theme to it.The basic purpose of doing this is to achieve the total control on what to show and what not in the dialog you create.

Related

How to change only one property of a BuiltInView?

I'm a Xamarin Android beginner. In an app that I'm writing, I created an Activity with a RadioGroup, and a button below it.
All was fine, until my radio buttons contained so much text that the radio group ran off the phone's screen, and the button was hidden.
So, I searched on the internet, and discovered that I could make the RadioGroup scrollable, by making it a ListView, and setting the ListView to be above the button.
Furthermore, I discovered that Xamarin Android offers the BuiltInView SimpleListItemSingleChoice which is a ready-made radio group as a ListView.
So, I implemented this, and all was fine, except that the text fields in each Item of the BuiltInView get cut short (i.e my radio button options to the user).
I want to apply the property
android:layout_height="wrap_content"
so that my long text labels for the radio buttons won't get cut short.
My question is, how do I apply this to each item of the BuiltInView?
I've tried to define my own custom view, but have run into problems trying to make it checkable, so I wondered if there is a simpler way to solve the problem by using the already provided BuiltInView.
In MyListAdapter GetView, I have
view = (context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItemSingleChoice, parent, false));
and in my Activity, I have
myListAdapter = new Adapters.MyListAdapter(this, myStrings, false);
myListView.Adapter = myListAdapter;
As the BuiltInView does not offer an xml file (or I don't know where to access it in Xamarin), I added the following code to the custom Adapter's GetView method:
var textLabel = view.FindViewById<TextView>(Android.Resource.Id.Text1);
//I added these 2 lines to set the WrapContent property on each element of the BuiltInView
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent,
AbsListView.LayoutParams.WrapContent);
textLabel.LayoutParameters = layoutParams;

List Dialog similar to Android L Notifications (Transparent ListView Divider?)

I have a dialog containing a dynamic ListView. I'm trying to style it similar to the Android L notifications center but I can't seem to do so.
My dialog window background is already transparent and the ListView content is set up but I can't seem to add transparent dividers to it. When I change my listview's divider color to transparent, it completely disappears removing the gap in between. After manually setting a divider height, it returns but it's not transparent. Instead, it's some sort of dark blue-ish transparent color.
My code for this is fairly simple:
// Create ListView
ListView mList = new ListView(context);
mList.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
// Create dialog base
final Dialog mDialog = new Dialog(context, R.style.TransparentDialog);
mDialog.setContentView(mList);
mDialog.setCanceledOnTouchOutside(true);
mDialog.setCancelable(true);
// Add listview content...
// ...
// Apply dividers and content
mList.setDivider(new ColorDrawable(R.color.transparent));
mList.setDividerHeight(72);
mList.setAdapter(mAdapter);
.
How would I go on to styling it like it? My only issue with this is the lack of transparent ListView divider.
This is what I'm trying to achieve:
I ended up achieving this effect using card images with transparent margins embedded in them.

Adding table layout to AlertDialog

I want to display an AlertDialog (button OK) with the content being a TableLayout.
However, I would like the TableLayout creation to be programatically, by Java, as I need to add rows depeding on some variables.
Any Idea how to do that?
Specifically:
1- Can an AlertDialog have TableLayout view, or does it only expect text so I should go with dialog?
2- How do I create TableLayout programmatically and add rows to it.
I have done it in xml but not sure in java
Help is appreciated
Thanks
Why don't you create a custom Dialog?
1 - You can instantiate a Dialog as in Dialog dialog = new Dialog(context, theme)
2 - Then you can make a dialog.setContentView(layout), find your tablelayout by id (dialog.findViewById)
3 - Then do what you need to do. I'd recommend putting this all in a separated method.
You should be able to set whatever layout you desire to the dialog using it 'setContentView' method.
You can inflate ui from an xml file. Like
LayoutInflater mInflater = LayoutInflater.from(context);
View yourView = mInflater.inflate(R.layout.your_layout, null);
alertDialog.setContentView(yourView);
The above code should work.

Can we have an edit text as a menu item in android 3.0 honeycomb

Can we have an edit text box inside our menu which gets displayed in the action bar
and if we can then how can we get click events on this edit text ?
I found the solution. It is done like this (only for android 3.0 honeycomb)
Placing an edit text in action bar
for placing the items
use this TAG in your item in the menu xml
android:actionLayout="#layout/search_bar"
define edit text & button in the search_bar layout.
Now for getting listeners on them do it like this -
in onCreateOptionsMenu()
et = (EditText) menu.findItem(R.id.search_bar).getActionView().findViewById(R.id.searchbar);
findBtn = (ImageButton)menu.findItem(R.id.search_bar).getActionView().findViewById(R.id.find);
and then place listeners for these items. It will work fine
You can add a search bar to the action bar but not as a menu item... what do you even meen with "as a menu item"?
I havent tried it but are you able to use actionlayout from code? in that way you could use get the Text box this way:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
LinearLayout wrapper = (LinearLayout) inflater.inflate(R.layout.random_layout, null);
EditText editText = (EditText )wrapper.findViewById(R.id.edit);
//
//code to set the listener
//
//
//set the android:actionLayout to wrapper etc.
//
Im at work so I can't make some research so this is just speculations...

Android - change custom title view at run time

I am using a custom title view in my application for each activity. In one of the activities, based on button clicks I need to change the custom title view. Now this works fine every time when I make a call to setFeatureInt.
But if I try to update any items in the custom title (say change the text of a button or a text view on the title), the update does not take place.
Debugging through the code shows that the text view and button instances are not null and I can also see the custom title bar. But the text on the text view or the button is not updated. Has anyone else faced this problem?
How do I resolve it?
Thanks.
EDIT
Here's what I tried. Does not get updated even on calling postInvalidate.
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.text_title);
TextView databar = (TextView) findViewById(R.id.title_text);
databar.setText("Some Text");
databar.postInvalidate();
Button leftButton = (Button) findViewById(R.id.left_btn);
leftButton.setOnClickListener(mLeftListener);
leftButton.setText("Left Btn");
leftButton.postInvalidate();
Button rightBtn = (Button) findViewById(R.id.right_btn);
rightBtn.setOnClickListener(mRightListener);
rightBtn.postInvalidate();
The problem is that the only Window implementation (PhoneWindow) uses a LayoutInflater in its setFeatureInt method and instantiates the new layout with inflate and attachToRoot=true. Consequently, when you call setFeatureInt, the new layouts are not replaced but attached to the internal title container and thus drawn on top of each other.
You can workaround this by using the following helper method instead of setFeatureInt. The helper simply removes all views from the internal title container before the new custom title feature is set:
private void setCustomTitleFeatureInt(int value) {
try {
// retrieve value for com.android.internal.R.id.title_container(=0x1020149)
int titleContainerId = (Integer) Class.forName(
"com.android.internal.R$id").getField("title_container").get(null);
// remove all views from titleContainer
((ViewGroup) getWindow().findViewById(titleContainerId)).removeAllViews();
// add new custom title view
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, value);
} catch(Exception ex) {
// whatever you want to do here..
}
}
I'm not sure whether the current setFeatureInt behaviour is intended, but it is certainly not documented one way or the other which is why I'll take this to the android devs ;)
EDIT
As pointed out in the comments, the aforementioned workaround is not ideal. Instead of relying on the com.android.internal.R.id.title_container constant you could simply hide the old custom title whenever you set a new one.
Let's assume you have two custom title layouts:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/custom_title_1" ...
and
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/custom_title_2" ...
and you want to replace custom_title_1 with custom_title_2, you could hide former and use setFeatureInt to add the latter:
findViewById(R.id.custom_title_1).setVisibility(View.GONE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_2);
The correct way to do this is as follows:
requestWindowFeature( Window.FEATURE_CUSTOM_TITLE );
setContentView( R.layout.my_layout );
getWindow().setFeatureInt( Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title );
super.onCreate( savedInstanceState );
Please note that the order of these statements is very important.
If you call super.onCreate() before any of the other statements you will get a blank title bar, which the hack of finding the title bar id and removing all the Views from it will fix but is not recommended.
Are you calling invalidate or postInvalidate to redraw the view after updating the text? If it's a custom View, can you put a breakpoint in the draw code to make sure it's getting called?
If you're on the UI thread, you can call 'invalidate' if you're not, you must call 'postInvalidate' or the view won't redraw itself.
Just my 2c worth:
When working in a MapActivity, requesting a custom title resulted in no title at all being shown.
Luckily, all I wanted to do was to set the title text differently, and I soon realized that just calling setTitle() inside of onCreate() worked for me (I called it after I called setContentView())
Sorry, but I don't have time right now to debug this any more and figure out why what I was doing didn't work, and why changing it made it work. As I said, just thought this might help someone out down the road.

Categories

Resources