In my Android app I have set up a common footer for all activity.
Implemented like this How do I create a header or footer button bar for my Android application with a top most Activity "MyActivity".
In my other activity I code as:
public class TestActivity extends MyActivity implements OnClickListener {
private static final String TAG = "TEST";
private AlertDialog.Builder builder = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
// Pick up the group from head_foot.xml for middle data to be displayed
ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
ViewGroup.inflate(Mumbai77Activity.this, R.layout.main, vg);
In other activity, child of MyActivity where I create an AlertDialog thru Inflate Layout and display, the height of AlertDialog should be less than the height reached footer. How do I handle the height of the AlertDialog.
The code I use for creating dialog is :
public AlertDialog createAlertDialog(String title, String[] items, OnItemClickListener clickListener) {
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// scrollview1 is the root of this activiy layout
ViewGroup vg = (ViewGroup) findViewById(R.id.scrollView1);
LinearLayout view = (LinearLayout) layoutInflater.inflate(R.layout.gen_list_layout, vg, false);
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="wrap_content" android:id="#+id/scrollView1"
android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
I tried setting LayoutParams in AlertDialog for the Viewgroup, but it also didn't work.
How to make the AlertDialog's height same as scrollview's or lldata's height?
Related
I'm using Vaadin 8 and I have a HorizontalLayout at the very top of the page. It's in a VeritcalLayout which is the main content of the UI.
Something like:
UI
VerticalLayout (margin=false, spacing=false)
HorizontalLayout (margin=false, spacing=false)
So you would expect everything to align to the edges of the browser viewport. I also have set default component alignment on everything to TOP LEFT.
Now, I want to put an image in the upper-right of that HorizontalLayout. The image aligns to the right of the screen as expected but the top of the image has about 30-40 pixels of padding that I cannot get rid of.
Imagine the black box as the logo I am using:
My UI init:
#SpringUI
#Theme("valo")
#PushStateNavigation
public class CustomUI extends UI implements ViewDisplay {
private static final long serialVersionUID = -3026091945679596519L;
#Autowired
private SpringViewProvider viewProvider;
#Autowired
private SpringNavigator navigator;
#Override
protected void init(VaadinRequest vaadinRequest) {
setSizeFull();
final VerticalLayout root = new VerticalLayout();
root.setMargin(false);
root.setSpacing(false);
root.setSizeFull();
setContent(root);
navigator.init(this, root);
}
#Override
public void showView(View view) {
this.setContent((Component) view);
}
My HorizontalLayout:
HorizontalLayout layout = new HorizontalLayout();
layout.setMargin(false);
layout.setSpacing(false);
layout.setHeight(64, Unit.PIXELS);
layout.setWidth("100%");
String basePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileResource logo = new FileResource(new File(basePath + "/WEB-INF/images/logo.PNG"));
Image logoImg = new Image("", logo);
layout.addComponent(logoImg);
layout.setComponentAlignment(logoImg, Alignment.TOP_RIGHT);
The image is 64 pixels tall. The HorizontalLayout is also 64 pixels tall according to the debugger.
But notice how far off it is on the top.
What am I doing wrong?
just change
Image logoImg = new Image("", logo);
into
Image logoImg = new Image(null, logo);
Components in a HorizontalLayout have their caption on top of the component. If the caption is not null, i.e. it is empty it does take the aforementioned 30-40 pixels.
For me it looks like it looks like that UI itself still has margin. So you need to disable in.
#Override
protected void init(VaadinRequest vaadinRequest) {
setSizeFull();
setMargin(false); // this was missing
final VerticalLayout root = new VerticalLayout();
root.setMargin(false);
root.setSpacing(false);
...
}
I want to call Content page class from Android .cs Class.
I use StartActivity(new Intent(Application.Context, typeof(LoginPage)));
showing error message
"System.ArgumentException: type Parameter name: Type is not derived
from a java type "
Does anyone know the solution for this? Please help me in Xamarin.Forms.
This should be you App.xaml.cs class
public App()
{
MainPage = new NavigationPage ( new MainPage());
}
MainActivity.cs file
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
private TextView setting;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
SetContentView(Resource.Layout.HomeScreen);
setting = FindViewById<TextView>(Resource.Id.settingText);
//check setting button is null or have value
setting.Click += delegate
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
};
}
}
Use code above & debug to check if setting button have instance or is null.
Replace typeof(LoginPage) with LoginPage.Class or LoginPage::Class.java (kotlin)
I have a Xamarin application, where my MainPage is a navigationpage (contentpage). In this navigationpage I open modals.
In the modals I open in my MainPage, I want to use Navigation.PushAsync but this requires the NavigationPage context which a modal page is not.
I've read that the flow would be:
Tell parent/caller to pop current visible modal
Tell parent/caller
to navigate to the page I want, using Navigation.PushAsync
However, how do you do this? How do you tell the parent to do this and actually do the navigation?
I would use event handlers to get this job done:
Here is an example code:
App.cs
public class App : Application
{
public App()
{
MainPage = new NavigationPage(new PushedNavigationPage());
}
}
PushedNavigationPage Page:
public class PushedNavigationPage: ContentPage
{
public PusehdNavigationPage()
{
}
public void DoPushModalOnButtonClick()
{
var pushedModalPage = new PushedModalPage();
pushedModalPage.DoPush += HandleDoPush;
Navigation.PushModalAsync(pushedModalPage);
}
private void HandleDoPush(object sender, EventArgs e)
{
Navigation.PopModalAsync();
Navigation.PushAsync(//the page you want to push)
}
}
PushedModalPage
public class PushedModalPage : ContentPage
{
public event EventHandler DoPush;
//call this on putton click or whenever you want
private void OnDoPush()
{
if (DoPush!= null)
{
DoPush(this, EventArgs.Empty);
}
}
}
I have not awaiting the async methods but it is better to do so and this is just an example, but I think you should get the idea..
I want to code a TextField component with icon.
So the behavior is as follow:
If the TextField contains an empty string, I use "lens.png".
Otherwise, i use "cross.png".
using the JavaFX Scene Builder, I added a TextFiled and an ImageView in the stack pane.
My code is the following:
#FXML
private TextField textSearch;
#FXML
private ImageView imageView;
final Image lensIcon = new Image("/issue/images/lens.png");
final Image crossIcon = new Image("/issue/images/cross.png");
//initialize () method
textSearch.textProperty().addListener(obs -> {
final String text = textSearch.getText();
Image icon = (text==null || text.isEmpty()) ? lensIcon : crossIcon;
imageView.setImage(icon);
imageView.setMouseTransparent(icon == lensIcon);
}
);
imageView.setOnMouseClicked(evt -> textSearch.setText(null));
my issue is the following:
How to prevent writing caracters below the icon (ImageView). the following figure illustrate my issue.
ControlsFX is an JavaFX API that supplies a ton of advanced controls UI that didn't come with JavaFX out of the box.
ControlsFX - http://fxexperience.com/controlsfx/
FontAwesomeFX supplies hundreds of icons (such as a cross in your case above)
FontAwesomeFX - https://bitbucket.org/Jerady/fontawesomefx/downloads/
Here is a demo solution to your problem after importing both these fantastic APIs
public class TextFields_Demo extends Application {
private Parent createContent() {
Pane root = new Pane();
CustomTextField customTextField = new CustomTextField();
FontAwesomeIconView icon = new FontAwesomeIconView(FontAwesomeIcon.CLOSE);
customTextField.setRight(icon);
root.getChildren().add(customTextField);
return root;
}
#Override
public void start(Stage primaryStage) {
Scene scene = new Scene(createContent());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I have to create a button to show an image. I created it using two activity, but I want that the button and the image view stay in the same page. So, I think I have to create only one activity, right? can you explain hot to do this? this is my code:
ACTIVITY ONE:
public class HomeWork extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_work);
Button getResultButton = (Button) findViewById(R.id.btn1);
getResultButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent resultIntent =new Intent(HomeWork.this,HomeWork2.class);
startActivity(resultIntent);
}
});
}
SECOND ACTIVITY:
public class HomeWork2 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_work2);
ImageView img=(ImageView)findViewById(R.id.imageView);
img.setBackgroundResource(R.drawable.apple);
}
the apk works correctly, the only problem is that I want button and imageview in the same image
Create a layout which contains both the Button and the ImageView.
Then in the Button's click listener, use
ImageView img=(ImageView)findViewById(R.id.imageView);
img.setBackgroundResource(R.drawable.apple);
instead of
Intent resultIntent =new Intent(HomeWork.this,HomeWork2.class);
startActivity(resultIntent);
Also remove (the now unused) HomeWork2 from your manifest.
[EDIT]
You may add more buttons, to change the contents of the ImageView.
You only have to put in their click listeners:
img.setBackgroundResource(R.drawable.orange);
or
img.setBackgroundResource(R.drawable.pineapple);
or ...