When a user want to paste text in MultiAutoCompleteTextView I want to overwrite it.
Means whatever he copies it must paste in my MultiAutoCompleteTextView as "Java is rocket".
I may achieve it from previous question here but I don't know how to hook the class MonitoringEditText to my MultiAutoCompleteTextView.
Can I achieve it or it is impossible.
You can do this using the same concept provided in the code from the link you provided. Extend the MultiAutoCompleteTextView and override the onTextContextMenuItem method.
Something along the lines of:
public class MonitoringMultiAutoCompleteTextView extends MultiAutoCompleteTextView {
public MonitoringMultiAutoCompleteTextView(Context context) {
super(context);
}
public MonitoringMultiAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MonitoringMultiAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
//based on http://stackoverflow.com/a/14981376/1566836
#Override
public boolean onTextContextMenuItem(int id) {
// Do your thing:
boolean consumed = super.onTextContextMenuItem(id);
// React:
if (android.R.id.paste == id) {
setText("Java is rocket");
}
return consumed;
}
}
Then change your MultiAutoCompleteTextView in your layout file to whatever.your.full.package.is.MonitoringMultiAutoCompleteTextView.
After that, any attempt to paste into your MultiAutoCompleteTextView will result in the text being changed to "Java is rocket"
Related
I am trying to customize the Google Cast SDK's Cast Dialog (shown when you tap the cast button and shows the list of available devices), but i haven't found a way to do it.
Currently, it just shows an AlertDialog with a list of the available devices to connect.
What i want to do instead, is open an Activity that will show the list of devices with my own UI implementation.
This is the dialog i am trying to modify:
I've found many customization aspects about this SDK, but nothing related to this dialog.
So i figured out a way to achieve this,
First i created a class that overrides MediaRouteActionProvider (which is the main class that controls that button's functionality)
public class CustomMediaRouteActionProvider extends androidx.mediarouter.app.MediaRouteActionProvider {
public CustomMediaRouteActionProvider(Context context) {
super(context);
}
#Override
public MediaRouteButton onCreateMediaRouteButton() {
return new CastButton(getContext());
}
}
Then you're gonna need to override the button's functionality with your own, in my case i open a new activity.
public class CastButton extends MediaRouteButton {
public CastButton(Context context) {
this(context, null);
}
public CastButton(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.mediaRouteButtonStyle);
}
public CastButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean performClick() {
Intent i = new Intent(getContext(), RemoteDevicesActivity.class);
getContext().startActivity(i);
return true;
}
}
Finally, you need to modify your xml that contains this button (i assume that you already implemented this part)
Change the field app:actionProviderClass with your custom class (in this case CustomMediaRouteActionProvider) and you're done.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="#string/connect_to"
android:id="#+id/cast"
app:actionProviderClass="CustomMediaRouteActionProvider"
app:showAsAction="ifRoom" />
</menu>
Are you have more details of final result of this? I need to do something similar but I don't get it how did you achieve it
Background
I have an App with multiple custom TextViews in it.
These four Custom TextViews are all set up like this:
public class TextView_Light extends android.support.v7.widget.AppCompatTextView {
public TextView_Light(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public TextView_Light(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public TextView_Light(Context context) {
super(context);
init();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Light.ttf");
setTypeface(tf ,1);
}}
I do have TextView_Bold, TextView_Light, TextView_Regular and TextView_Thin. Each of them uses another font which is saved in assets/fonts
I use the TextViews like that:
<de.mayr.wap.app.helper.TextView_Light
android:id="#+id/textView_Light7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/overviewViaBarcode"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
When the App is started and a view shows up for the first time everything looks great, like that:
The Problem
In this view the user klicks on one of the tablerows, an Dialog appears where the user types in some data. On save the onResume method of the view is called, which calls an Webservice etc. like that:
#Override
public void onResume() {
super.onResume();
callSerNrWS();
}
public void callSerNrWS() {
if (CheckNetwork.isNetworkAvailable(getContext())) {
final AsyncResponseFortschritt<ResponseObject<PruefauftraegeVO>> response = new AsyncResponseFortschritt<ResponseObject<PruefauftraegeVO>>() {
#Override
public void processFinishSerNr(ResponseObject<PruefauftraegeVO> output) {
anw = createPruefAnwArraylist();
seriennummerVO = findDataToSerNr();
adapt = new PruefAnwAdapter(getContext(), anw, seriennummerVO);
pruefListView.setAdapter(adapt);
setVisibilityLoadAnimation(View.GONE);
if (output.getException() != null && !output.getException().isEmpty())
AlertCreator.makeFailAlert(R.string.titelKeinFortschritt, R.string.textKeinFortschritt,getContext());
}
#Override
public void processStartSerNr() {
setVisibilityLoadAnimation(View.VISIBLE);
}
};
AsyncCallSerNrWS ws = new AsyncCallSerNrWS(response, pruefauftraegeVO);
ws.execute();
}
}
And after that, theres in 90% of cases one or more TextView which changed its looking from eg. TextView_Light to TextView_Thin. Like in the following picture: The appearence of the 'Anzugstrom [A]' in the third row now looks like a TextView_Thin and the '9/48' in the fifth row looks like a TextView_Light
What I know
This doesnt happen when the view is shown for the first time
There isn't any system behind it. It's totally random.
It happens in activitys and fragments
It happens in every view i have whatever the TextView contains 'hard-coded' text or text that comes from an Webservice
Its not just in lists, also in 'normal' views
I'm using Android SharedPreferences API to build a settings screen.
I've one setting which I need a long text to explain the user its meaning (I would like to have something like main title and smaller subtitle,but i think it would require to much customization)
the settings.xml is like:
<EditTextPreference
android:defaultValue="15"
android:inputType="number"
android:icon="#drawable/ic_timer"
android:key="#string/pref_comment_interval"
android:persistent="true"
android:lines="2"
android:title="#string/time_between_comments" />
but even setting lines=2 and breaking the line with \n at time_between_comments the text is getting wrapped.
<string name="time_between_comments">Time between comments (in seconds)\nLower is faster</string>
like:
how can i make the text to break the line?
By default, the title of EditTextPreference is singleLine="true"
So we should custom it as below
public class MultiLineTitleEditTextPreference extends EditTextPreference {
public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MultiLineTitleEditTextPreference(Context context) {
super(context);
}
#Override
protected void onBindView(View view) {
super.onBindView(view);
TextView textView = (TextView) view.findViewById(your_package.R.id.title);
if (textView != null) {
textView.setSingleLine(false);
}
}
}
This doesn't work for all Preference types, but it works for EditTextPreference.
Add <![CDATA[ \n]]> around the first line of your title like in this example:
<string name="pref_title_special_with_note"><![CDATA[Special Title\n]]><small><i> ** followed by second line note</i></small></string>
This will display the second line in smaller text size and italic, but that's just decoration.
I am using autocomplete textview with arraylist value [aaa0,aaa1,...aaa100,aab0,aab1,...,aab100], I enter value 'aa' and scroll down till next 10 value ie.'aa10'and then i enter value 'aab' the suggestion list starts from 10th value i.e 'aab10'.
I have to scroll up to see the first value i.e 'aab0'.I want first value of suggestion list to appear when i change the search text.suggestion list screenshot
You need to extend the AutoCompleteTextView class
and override the onFilterComplete method
where you have to dismiss and show the drop down again to refresh the list view.
Also I would suggest instead of extending AutoCompleteTextView
extend the android.support.v7.widget.AppCompatAutoCompleteTextView
for obviously better support
here's the code
package your.package.name;
import android.content.Context;
import android.util.AttributeSet;
import android.support.v7.widget.*;
public class CustomAutoCompleteTextView extends AppCompatAutoCompleteTextView {
public CustomAutoCompleteTextView(Context context) {
super(context);
}
public CustomAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public void onFilterComplete(int count) {
super.onFilterComplete(count);
//show and dismiss the drop down to refresh the list in it
this.dismissDropDown();
this.showDropDown();
}
}
EDIT
Also you can use the AutoCompleteTextView.setListSelection() method to scroll to the top.
Instead of dismissing and showing the DropDown on every filter
which is more efficient.
#Override
public void onFilterComplete(int count) {
super.onFilterComplete(count);
//set list selection to 0
if(getListSelection() != 0)
this.setListSelection(0);
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to change the Font Size in a whole Application programmatically, Android?
This is my Code : I have created Spinner with a list of FontSize options. If I click FontSize "26" then it should be able to change in that specific FontSize. Below I have an EditBox. So if I clicked Fontsize as 40 and in a Italic style than usual Bold. So I should be able to type inside EditBox with this selected "Font" : FontSize "40" and Italic style.
How could I do this programmatically in Android?
font=new Spinner(con);
option= new String[] {"Select Font Size","8","10","12","14","16","18","20",
"22","24","26","28","30","32","34","36","38","40","50"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(con,android.R.layout.simple_spinner_dropdown_item,option);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
font.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id) {
option[1]="8";
selectedItem= option[position];
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
to change
textSize use editText.setTextSize(20)
font and style use editText.setTypeface(yourTypeFace, Typeface.BOLD)
UPDATE
public class MyEditText extends EditText{
public MyEditText(Context context) {
super(context);
init();
}
public MyEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
void init() {
this.setTextSize(20);
this.setTypeface(yourTypeFace, Typeface.BOLD);
}
// method to change font settings
void setFont(TypeFace tf){
this.setTypeFace(tf);
}
//add whatever method you want
}
and then instead of using EditText you use this class, and don't forget in your XML to use
<yourpackage.MyEditText
android:layout_height=".."
android:layout_width=".."
... />
The probable solution would be you create a base class which extends TextView, and use this text view class as edit text. Hope you are asking for size in first screen. In any case, u set the text size in the base class. This will solve your problem.
like u create this class in package com.example and class name is BaseTextView, then in xml file instead of you will write
Hope this helps.
First of all get the id of the EditBox.
Then selected item's position. according to that you can make a formula like this:
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id) {
int p=(8+(pos*2));
editText.setTextSize(p);
}