Achartengine: setClickListener() on x labels - android

I use Achartengine 1.1.0. Is posible to setClickListener() on x label's view? For exemple when i click "Dec" i want to show a toast: "December =14240"

There is not any direct method to get the touch event on labels.
But by getting the touched position and implementing this, you can achieve what u want.
You will need to check that position touched is of ur label.
Then do what u want.
To get the touched position see this
aChartEngine: getting coordinates of any point on the graph area
Also u can use
mChartView.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
System.out.println("X :" + mChartView.toRealPoint(0)[0]);
System.out.println("Y :" + mChartView.toRealPoint(0)[1]);
}
});
and check x.y values for labels positions.

Related

SciChart: catch click on Legend checkbox to hide series yAxis

I am working on the CreateMultiPaneStockChartFragment example and I want to catch the event when user check/unchecks checkbox in the legend so I can hide/show the yAxis of the series.
Let's say user unchecks RSI series. The series hide automatically, but a big empty space is now there. In my case I want to completely hide the area and other charts should become bigger to fill the empty space.
I don't know if this is right approach;
I modified RightAlignedOuterVerticallyStackedYAxisLayoutStrategy so that I can set different axis heights. Now I need to catch checkbox events - how?
Have you tried the approach suggested in this question from SciChart forums? You'll need to customize content of OnClickListener for checkBox:
checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
IRenderableSeries renderableSeries = seriesInfo.renderableSeries;
renderableSeries.setIsVisible(((CheckBox) view).isChecked());
renderableSeries.invalidateElement();
}
});
To get access to chart instance ( and then from it to axis ) from listener you can use next code:
BaseRenderableSeries renderableSeries = (BaseRenderableSeries) seriesInfo.renderableSeries;
final ISciChartSurface parentSurface = renderableSeries.getParentSurface();
Hope this will help you!

MPAndroidchart how to display label inside MarkerView?

I am using MPAndroidChart and I want to show values of xlabes and ylabes with markerview, I have shown the value of y-axis. And I don't konw how to show the value of x-axis(xVals), Can u show me how to do this or give me some tutorial links? Thanks a lot
I suggest you just hand your array of x-values to the MarkerView.
Then in the refreshContent(...) method:
#Override
public void refreshContent(Entry e, Highlight highlight) {
String xValue = xValuesArray.get((int) e.getX());
}

Sprite text at incorrect position

I'd like to add text to a working button. Currently, the code below prints the text at 0,0 rather than on the sprite button.
soundButton.graphics.beginFill(0xFFCC00);
soundButton.graphics.drawRect(0,900, 200, 50);
soundButton.graphics.endFill();
this.addChild(soundButton);
var soundtext:TextField = new TextField();
soundtext.text ="Sound On"; // default value
soundButton.addChild(soundtext);
soundButton.addEventListener( MouseEvent.CLICK,sound_CLICK);
Additionally, I'd like to add code to the listener below to have the button text reflect the state of the boolean doSound.
private function sound_CLICK (event:MouseEvent):Void {
doSound = !doSound;
// swap sprite button text Sound on/Sound off
}
Use the x and y property's of the Text Field to position the text on the button?
If there's something I'm missing ill update my answer.

show selection pointers and highlight text in textview with longclick

I have a TextView that I want to implement LongClickListner on and select part of the text in it... However selection pointers don't appear and the text is not highlighted.
I know the text is selected because when I use view.getselectionstart() and view.getselectionend() they return the right values...below the code I use:
textView.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Selection.setSelection((Spannable) textView.getText(),5, 10);
v.setSelected(true);
return true;
}
});
This doesn't show any thing.....But when I try to log selection start and end:
Log.d("SELECTED TEXT LISTNER",Selection.getSelectionStart(textView.getText())
+ " " +Selection.getSelectionEnd(textView.getText()));
the right values (5, 10) are returned...any help how I can show selection pointers and highlight on longclick??
In XML:
android:textIsSelectable="true"
Programatically:
textView.setTextIsSelectable(true);
You won't need to implement your own onLongClickListener as the default behaviour is as you described.

In Android SDK - How can I locate the word at a pixel location pressed by the user in an EditText

I am building an application where the user enters text into an EditText.
I would like to be able to have the user touch a word, and detect the word at the pixel location they touched. Is there any way to do this?
Thanks, Victor
Try this code...
public boolean onTouch(View view, MotionEvent mEvent) {
Layout layout = ((TextView) view).getLayout();
int x = (int)mEvent.getX();
int y = (int)nEvent.getY();
if (layout!=null){
int line = layout.getLineForVertical(y);
int charAtTouch = layout.getOffsetForHorizontal(line, x);
Log.i("position", "" + charAtTouch);
}
return true;
}
You may want to take a look at Spans. Particularly, ClickableSpan. You can assign a span to a part of the text to give that part of the text some "features" (in this case, it will make the text clickable).
There's a nice example, in which custom Spans extending ClickableSpan are used in EditText to make the text display more user-friendly.
May be you can get position of cursor appeared in textbox after touch and locate the word?

Categories

Resources