My view (Show Result) is defined in plugin.xml. Which is working as expected when I run the plugin Show Result widget is getting displayed. Now I want to load the view dynamically based on results. Such as for each result it should load the new Show Result (e.g Show Results1, Show Results2 etc) widget.
Any suggestion on how it can be achieved?
<view
allowMultiple="true"
class="com.eclipse.plugin.MyResultView"
icon="icons/res.png"
id="view1"
name="Show Results"
restorable="true">
</view>
If you want to show multiple instances of the same view use the
IViewPart showView(String viewId, String secondaryId, int mode);
method of IWorkbenchPage. The view needs to be defined with allowMultiple="true" in the plugin.xml.
The secondaryId is a arbitrary string that distinguishes the views, it can have any value (except it should not contain a :).
To set the name of the view call the ViewPart.setPartName(String name) method in the view part.
Related
I am trying to create a like and dislike button. I use Checkboxes to do so.
In the XML code I have two checkboxes one called like and the other dislike
I'm trying to toggle between the like and dislike buttons. Such that they both cannot be switched on at the same time.
public void onLike(View view) {
if (dislike.isChecked()) {
dislike.setChecked(false);
}
Toast.makeText(this,"liked",Toast.LENGTH_SHORT).show();
}
The issue that I am having is that set setChecked(true) is not doing anything.
For more context, the XML for the checkbox is defined inside a fragment that has a cardview. Each item in the card view has the checkboxes.
the way I initialized the checkbox in the main activity is as follows: -
View cardViewLayout = getLayoutInflater().inflate(R.layout.text_row_item,null);
like = (CheckBox) cardViewLayout.findViewById(R.id.like);
dislike = (CheckBox) cardViewLayout.findViewById(R.id.dislike);
any ideas what's going on?
ok, I've figured out the solution. Since I am using a recycler view with a custom adapter I need to bind the onClick listener via an interface.
Here is a link to another post that will show the necessary steps to implement click listeners in adapters: https://stackoverflow.com/a/49969478/11379938
I have a separate layout that I want to call onClick and update a field on callback
<include
android:onClick="#{() -> viewModel.changeItem(2)}"
layout="#layout/item"
app:attr="#{viewModel.title}"
app:desc="#{viewModel.description}"
app:active="#{viewModel.isSelected}"
/>
But it returns the following binding error:
Cannot find the setter for attribute 'android:onClick' with parameter
type lambda on com.X.databinding.ItemBinding.
But I can binding on other views
<TextView
android:onClick="#{() -> viewModel.changeItem(1)}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
What I suggest you is to call the onClick directly from code.
Setup an ID for your view in your .xml, then set something like this :
val item = findViewById(R.id.your_id) etc.
item.onClick { functionYouWantToCall() }
However, I do not know if this is possible to set an ID or an onClickListener on an include layout.
If you can not do it, simply put your include inside a LinearLayout, then set your onClick on it.
I used to set onClicks in the .xml too, but I think it is much more efficient to set it in the code.
Moreover, I do not know if you can set arguments in a function you call from the xml.
I'm completely new to Android application programming, and I was reading through Google's tutorial: http://developer.android.com/training/basics/firstapp/starting-activity.html.
On this page, under the "Display the Message" section, they create TextView object, and use setContentView with the textView object as the argument, to display some text. I was wondering, if I'm understanding correctly, instead of creating the TextView object within the code, can you define it in XML instead? If you define it in XML, would that require you to create a new XML file besides main_activity.xml? Thanks.
You can declare all your layouts and views inside a xml. For the given example, the code would look like the following
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set your parent view
setContentView(R.layout.main_layout);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Get the reference to the TextView and update it's content
TextView textView = (TextView)findViewById(R.id.my_text_view);
textView.setText(message);
}
And your main_layout.xml would look like
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:id="#+id/my_text_view"/>
You can arbitrarily create view files (XML files) and specify the primary type of the view and the children it contains. You could create the TextView element within the main_activity.xml view and find it by the relative Id.
That being said in the article in question if you want to have a separate view for just the TextView element then you would likely need another XML file to define that view if you do not want to specify it programmatically.
In a standard application you will likely have a predefined view (XML file) that you will set as the content view and reference elements from within it (as well as possibly add new elements).
It is very flexible, in short to answer your question no, you do not need to generate a new XML view file, you could simply add a TextView to an existing view file or specify it at runtime.
I have an edittext and I would like to paste some text in it. I can copy the text from some web page but I am not able to paste the text in my edittext control.How can I enable my edittext to paste some text.Here is my main.xml for edittext ;
enter code here
<EditText
android:id="#+id/enter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight= "2"
android:scrollbars="vertical"
android:textColor="#color/black"
/>
Thanks
This is on Android 4.4.2 Samsung S4;
Documentation for TextView says that:
To allow users to copy some or all of the TextView's value and paste
it somewhere else, set the XML attribute android:textIsSelectable to
"true" or call setTextIsSelectable(true). The textIsSelectable flag
allows users to make selection gestures in the TextView, which in turn
triggers the system's built-in copy/paste controls.
There is also another Textview attribure called android:cursorVisible which determines if the system should be invoked about the copy/paste callbacks.
By default I believe both of these are true and selection/copy/paste mechanics are already enabled. I could not change that behaviour by using android:textIsSelectable="false" but if I set android:cursorVisible="false" initially you can't paste anything inside the EditText. Only after you type something in, cursor and selection behaviour becomes enabled again. Maybe this should be handled inside the code rather than in the layout xmls, or it might be related to android:inputType which also did not make a difference for me.
So try setting android:cursorVisible="true" in your EditText's layout xml if paste is not enabled by default.
According to your problem if you copied some data any where in your system and you want to paste it in some specific variable, like Edit TextBox, Textview etc, then this code will surely help you.
ClipboardManager clipMan = (ClipboardManager)getSystemService(v.getContext().CLIPBOARD_SERVICE);
myEdtTxt.setText(clipMan.getText());
Note:- here the clipMan object will store the data whenever copied process take place and we will return that data from that object and will set it,
To enable the standard copy/paste for TextView, U can choose one of the following:
Change in layout file:
Either add below property to your TextView
android:textIsSelectable="true"
and In your Java class write this line to set it programmatically.
myTextView.setTextIsSelectable(true);
if fragment try with
mContext.myTextView.setTextIsSelectable(true);
And long press on the TextView you can see copy/paste action bar.
Try setting the inputType="text" for the EditText field
I am working on an app and need to add a textbox to the View when a button is selected. How can I do that or add any object dynamically. What class do I use or what method do I need to call? Thanks.
You just need to call the addView method to the target view. It's a method inherited from ViewGroup, see [here][2].
[2]:http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, android.view.ViewGroup.LayoutParams)
One possibility is to define it in your layout XML, and set:
android:visibility="gone"
Then in your code you can do:
TextView myTextBox = (TextView) findViewById(R.id.myTextBoxId);
myTextBox.setVisibility(View.VISIBLE);
and to hide it again:
myTextBox.setVisibility(View.GONE);
Here is the documentation