Text Gets Cut Off in Android DialogFragment - android-dialogfragment

The bottom half of the text contained in my DialogFragment is getting cut off. This is what it looks like:
Does anyone know what I am doing wrong, and how to fix it? Below is my current setup:
MainFragment.kt
class MainFragment(private val screenField: String): DialogFragment() {
private lateinit var mBinding: FragmentMainBinding
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
mBinding = FragmentMainBinding.inflate(LayoutInflater.from(context))
mBinding.screenField.text = screenField
return AlertDialog.Builder(context!!)
.setView(mBinding.root)
.setPositiveButton(R.string.ok, null)
.create()
}
override fun onStart() {
super.onStart()
val width = resources.getDimensionPixelSize(400dp)
val height = resources.getDimensionPixelSize(150dp)
dialog?.window?.setLayout(width, height)
}
}
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/screen_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="#android:color/black"/>
</LinearLayout>

Related

DatePicker with Databinding and Rxjava Observable view does not save to Realm on different Android Versions

The codes below runs in an android emulator with Android version SDK 16. But somehow when it runs on the emulator with Android version >21, DataBinding and Realm savings doesn't get triggered..
How should I be dealing with Android versioning?
Is it because the rendered UI differs in different android versions so DataBinding wouldn't have worked either?
This code here is the ViewModel
#PerFragment
public class OnboardDOBViewModel extends BaseHelperViewModel<BaseUserView> implements IOnboardDOBViewModel {
private String TAG = getClass().getSimpleName();
private HelperRepo mHelperRepo;
private UserRepo mUserRepo;
private Helper mHelper;
public final ObservableField<Integer> datePicker = new ObservableField<>();
public final ObservableField<Integer> monthPicker = new ObservableField<>();
public final ObservableField<Integer> yearPicker = new ObservableField<>();
public ReadOnlyField dobSelected;
private CompositeDisposable mCompositeDisposable = new CompositeDisposable();
#Inject
public OnboardDOBViewModel(#AppContext Context context, UserRepo userRepo, HelperRepo helperRepo) {
super(context, userRepo, helperRepo);
Log.d(TAG, "OnboardDOBViewModel: ");
this.mUserRepo = userRepo;
this.mHelperRepo = helperRepo;
}
#Override
public void attachView(BaseUserView view, #Nullable Bundle savedInstanceState) {
super.attachView(view, savedInstanceState);
Log.d(TAG, "attachView");
mHelper = mHelperRepo.getByUser("user.id", mUserRepo.getCurrentUser(), false);
if (mHelper != null) {
Calendar c = Calendar.getInstance();
yearPicker.set(c.get(Calendar.YEAR)-23);
monthPicker.set(c.get(Calendar.MONTH));
datePicker.set(c.get(Calendar.DAY_OF_MONTH));
}
Observable<String> dobSelected = Observable.combineLatest(
Utils.toObservable(monthPicker),
Utils.toObservable(datePicker),
Utils.toObservable(yearPicker),
(integer, integer2, integer3) -> {
String dobSelected1 = String.valueOf(monthPicker.get() + 1) + "-" +
datePicker.get().toString() + "-" +
yearPicker.get().toString();
Log.d(TAG, "apply: " + dobSelected1);
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy", Locale.getDefault());
Date date = sdf.parse(dobSelected1);
Log.d(TAG, "apply: date selected" + date);
Helper helper = mHelperRepo.getByUser("user.id", mUserRepo.getCurrentUser(), true);
assert helper != null;
helper.setDateOfBirth(date);
mHelperRepo.save(helper);
return dobSelected1;
});
this.dobSelected = Utils.toField(dobSelected);
}
This is the XML
<data>
<variable
name="vm"
type="...OnboardDOBViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="30dp"
android:text="#string/toolbar_title_date_of_birth"
android:textAppearance="#style/TextAppearance.AppCompat.Large" />
<DatePicker
android:id="#+id/onboard_birth_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:calendarViewShown="false"
android:day="#={vm.datePicker}"
android:month="#={vm.monthPicker}"
android:solidColor="#color/grayMedium"
android:spinnersShown="true"
android:year="#={vm.yearPicker}" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="test"
android:text="#{vm.dobSelected}"
android:visibility="visible"/>
</LinearLayout>
Found this as my answer
OnDateChanged is not called in Date picker Android lollipop
added this in, and override the config, calendar UI is now spinner style and binding works
android:datePickerMode="spinner"

Adding image and childitem in a listview in android

I'm a beginner to android n m tryin to display a listview wer i'll have an image, items n subitems(childitem).. i tried it but m unable to c the image and the subitem of the list.. here's my code :-
activity_main :-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
listview_layout:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/flag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/hello"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
/>
<TextView
android:id="#+id/cur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
/>
</LinearLayout>
MainActivity :-
public class MainActivity extends Activity {
// Array of strings storing country names
String[] countries = new String[] {
"India",
"Pakistan",
"Sri Lanka",
"China",
"Bangladesh",
"Nepal",
"Afghanistan",
"North Korea",
"South Korea",
"Japan"
};
// Array of integers points to images stored in /res/drawable-ldpi/
int[] flags = new int[]{
R.drawable.india,
R.drawable.pakistan,
R.drawable.srilanka,
R.drawable.china,
R.drawable.bangladesh,
R.drawable.nepal,
R.drawable.afghanistan,
R.drawable.nkorea,
R.drawable.skorea,
R.drawable.japan
};
// Array of strings to store currencies
String[] currency = new String[]{
"Indian Rupee",
"Pakistani Rupee",
"Sri Lankan Rupee",
"Renminbi",
"Bangladeshi Taka",
"Nepalese Rupee",
"Afghani",
"North Korean Won",
"South Korean Won",
"Japanese Yen"
};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Each row in the list stores country name, currency and flag
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<10;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("txt", "Country : " + countries[i]);
hm.put("cur","Currency : " + currency[i]);
hm.put("flag", Integer.toString(flags[i]) );
aList.add(hm);
}
// Keys used in Hashmap
String[] from = { "flag","txt","cur" };
// Ids of views in listview_layout
int[] to = { R.id.listview,R.id.txt,R.id.cur};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
// Getting a reference to listview of main.xml layout file
ListView listView = ( ListView ) findViewById(R.id.listview);
// Setting the adapter to the listView
listView.setAdapter(adapter);
// Item Click Listener for the listview
OnItemClickListener itemClickListener = new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View container, int position, long id) {
// Getting the Container Layout of the ListView
LinearLayout linearLayoutParent = (LinearLayout) container;
// Getting the inner Linear Layout
LinearLayout linearLayoutChild = (LinearLayout ) linearLayoutParent.getChildAt(1);
// Getting the Country TextView
TextView tvCountry = (TextView) linearLayoutChild.getChildAt(0);
Toast.makeText(getBaseContext(), tvCountry.getText().toString(), Toast.LENGTH_SHORT).show();
}
};
// Setting the item click listener for the listview
listView.setOnItemClickListener(itemClickListener);
}
In the output the listview just displays the country name.. the image and the currency values are not displayed.. wht m i missin ?

TextView and Button in a row of listview xamarin c#

I have a listview in which I have a textview, an image and a button in a row in Xamarin using c#. by clicking on button I need to open a new layout:
this is axml for listview: called "Friends"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="378.2dp"
android:id="#+id/listView1" />
</LinearLayout>
this is axml for each row in listview: called "Row1"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="81.1dp"
android:id="#+id/linearLayout1">
<ImageView
android:src="#drawable/Icon"
android:layout_width="91.7dp"
android:layout_height="match_parent"
android:id="#+id/imageView5" />
<TextView
android:text="Text"
android:layout_width="184.9dp"
android:layout_height="35.6dp"
android:id="#+id/textView1"
android:gravity="center"
android:textSize="20dp" />
<Button
android:text="Chat"
android:layout_width="62.3dp"
android:layout_height="37.8dp"
android:id="#+id/chat1"
android:layout_marginTop="32dp" />
</LinearLayout>
</LinearLayout>
and this is the activity for listview: called "FriendsActivity"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace EJIK_Network
{
[Activity (Label = "FriendsActivity")]
public class FriendsActivity : Activity
{
ListView listview;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Friends);
listview = FindViewById<ListView> (Resource.Id.listView1);
View rootInAnotherLayout = this.LayoutInflater.Inflate (Resource.Layout.Row1,null);
Button chat = rootInAnotherLayout.FindViewById<Button> (Resource.Id.chat1);
chat.Click += (sender, e) => {
var CA = new Intent(this, typeof(ChatingActivity));
StartActivity (CA);
};
}
}
}
The cod run but when I clicked on chat button it didn't open the new layout wich I defined in "ChatingActivity"??????
You have to create a Custom Adapter and inside the GetView method:
public override View GetView(int position, View convertView, ViewGroup parent) {
var view = (convertView ??
this._context.LayoutInflater.Inflate(
Resource.Layout.Row1,
parent,
false)) as LinearLayout;
Button chat = view.FindViewById<Button> (Resource.Id.chat1);
chat.Click += (sender, e) => {
var CA = new Intent(this, typeof(ChatingActivity));
StartActivity (CA);
};
}
So clicking on the chat button of each list item, the ChatingActivity will start.

How to select the rating bar in List Adapter in android?

Eventhough this question has been asked by users many number of times,I am not able to solve my problem by going through all the posts.I have used list view in android.And to the listview i have added the rating bar,text view and some other child items.I am able to select only the entire list item.I want to select the individual list items.I will paste the code which i have tried.
public class ReviewAdapter extends ArrayAdapter<String>{
private final Context context;
private final String[] values;
public ReviewAdapter(Context context, String[] values) {
super(context,R.layout.activity_reviewlist,values);
this.context = context;
this.values = values;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView =layoutInflater.inflate(R.layout.activity_reviewlist, parent,false);
TextView tv1 = (TextView) rowView.findViewById(R.id.textView1);
TextView tv2 = (TextView) rowView.findViewById(R.id.textView2);
TextView tv3 = (TextView) rowView.findViewById(R.id.textView3);
TextView tv4 = (TextView) rowView.findViewById(R.id.textView4);
TextView tv5 = (TextView) rowView.findViewById(R.id.textView5);
RatingBar ratingbar = (RatingBar) rowView.findViewById(R.id.ratingBar1);
ratingbar.setIsIndicator(true);
ImageView im1 = (ImageView) rowView.findViewById(R.id.imageView1);
tv1.setText(values[position]);
String s = values[position];
if(s.equals("Speech for Presentation")){
tv2.setText("07 th May 2011 22:30");
tv3.setText("05:30");
tv4.setText("Attempts");
tv5.setText("5");
}
else if(s.equals("Slide Show Presentation")){
tv2.setText("08 th May 2011 21:15");
tv3.setText("04:12");
tv4.setText("Attempts");
tv5.setText("7");
}
else if(s.equals("Seminar Presentation")){
tv2.setText("09 th May 2011 10:15");
tv3.setText("08:26");
tv4.setText("Attempts");
tv5.setText("9");
}
else if(s.equals("Training Speech")){
tv2.setText("10 th May 2011 9:16");
tv3.setText("09:26");
tv4.setText("Attempts");
tv5.setText("3");
}
else{
tv2.setText("12 th May 2011 10:10");
tv3.setText("19:26");
tv4.setText("Attempts");
tv5.setText("7");
}
return rowView;
}
}
And now i am going to paste my list activity here
public class ReviewActivity extends ListActivity {
static final String[] reviews = new String[] {"Speech for Presentation","Slide Show Presentation","Seminar Presentation","Training Speech","Promoting the product"};
protected void onListItemClick(ListView l, View v, int position, long id) {
//get selected items
String selectedValue = (String) getListAdapter().getItem(position);
Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ReviewAdapter(this, reviews));
}
}
Lastly iam pasting the xml which i have tried.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RatingBar
android:id="#+id/ratingBar1"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:layout_marginTop="33dp"
android:isIndicator="true"
/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/ratingBar1"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="26dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/textView2"
android:src="#drawable/timer" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/imageView1"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView3"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#+id/textView3"
android:text="TextView" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView4"
android:layout_alignRight="#+id/ratingBar1"
android:text="TextView" />
</RelativeLayout>

Display two webview in one screen

i'm trying to make a webview app which can display two website in one screen. but when i run my app it display one website and open on new browser. how can i display two website and it doesn't work on new browser?
this is my WebViewActivity class:
package com.mkyong.android;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
private WebView webView1, webView2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView1 = (WebView) findViewById(R.id.webView1);
webView1.getSettings().setJavaScriptEnabled(true);
webView1.loadUrl("http://www.google.com");
webView2 = (WebView) findViewById(R.id.webView2);
webView2.getSettings().setJavaScriptEnabled(true);
webView2.loadUrl("http://www.google.com");
}
}
this is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.39" />
<WebView
android:id="#+id/webview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.53" />
</LinearLayout>
I suggest you use framelayout and try to set webviewClient to your webview
this function shouldOverrideUrlLoading (in the declaration of the webviewClient)
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i("Page", url);
view.setWebViewClient(new MyWebViewClient());
view.setWebChromeClient(new MyWebChromeClient());
view.loadUrl(url);
return true;
}
will override url loaded by the webview and force it to be loaded in the webview not in the new browser