I want to input data i.e. name and age of user on a scene of AndEngine. How can I do that ??
I dont want to use a dialog for this purpose.
You asked this on the AndEngine forums and RealMayo gave you the best answer there.
Study the TextBreakExample.java - and more specifically, study the AndEngineExamples/res/layout/textbreakexample.xml file
You will see how to "blend" a standard Android EditText (not a dialog) into your game.
If all you want to do is a text entry overlay, you can add it in your onSetContentView() method:
#Override
protected void onSetContentView() {
editTextExample = new EditText(this);
this.addContentView(editTextExample, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
}
Otherwise, if you want to make editable text whose look can be set by AndEngine, check out the example Java code and XML code
Related
I have tried to show the dialog box while the user giving the wrong username or password, using the below code.
private void showAlert(String title, String msg) {
customDialog = new Dialog(LoginActivity.this,
android.R.style.Theme_Dialog);
customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
customDialog.setContentView(R.layout.custom_alert_dialog);
tvTitle = (TextView) customDialog
.findViewById(R.id.dialog_title);
tvMsg = (TextView) customDialog
.findViewById(R.id.dialog_message);
btnNeutral = (Button) customDialog
.findViewById(R.id.closeAlert);
tvMsg.setText(msg);
tvTitle.setText(title);
tvMsg.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
tvMsg.setFocusable(true);
btnNeutral.setText("Close");
btnNeutral.setVisibility(View.VISIBLE);
btnNeutral.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
customDialog.dismiss();
}
});
customDialog.show();
tvMsg.requestFocus();
}
The code working fine but my concern is, when i am trying to use the android talkback. It reads only the title of the dialog box. The talkback needs to read the content(message) of the dialog box instead of title. Can anyone help me to do this?
First, announcing just the title of a new dialog is very standard. Doing otherwise would probably be counter productive in terms of accessibility. This sounds to me like an accessibility requirement from someone motivated to do good, that doesn't really understand the needs of users with disabilities. Shoving focus around arbitrarily is usually bad. Let the operating system do what it wants with focus, it is what Assistive Technology (TalkBack) users will be accustomed to.
This said there are two overarching issues with your code. First, when you say focus, you mean accessibility focus.
tvMsg.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
tvMsg.setFocusable(true);
tvMsg.requestFocus();
All of these lines are referring to keyboard, or input focus, none of which are particularly meaningful for a TextView. These are only meaningful for active elements like Buttons and EditText boxes. Will this work if you do it correctly, yes. But, it comes with awkward side effects, like a TextView being added to Tab ordering, which is awkward for Keyboard only users, because TextViews don't have focus highlights, so Focus navigation disappears. What you really want is the following event type:
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED
Now, for the second point. You're doing all of this before your view actually renders. Replace this line:
tvMsg.requestFocus();
With this line:
tvMsg.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
Delete the other lines mentioned above, and you should be golden. Though, again, my ultimate recommendation would just be dropping all of this, and removing those three lines outright, and forgetting about this. Let the operating system do its thing!
I want to create a link in text view.
My link look like so:
The text to the link I get from array.xml
<item>Icons made by Freepik</item>
I already read set movement method
textView.setMovementMethod(LinkMovementMethod.getInstance());
This has no impact
and
android:autoLink="web"
This works if the text is http://www.freepik.com, but not if I want to have a custom text as link.
viewHolder.textView.setClickable(true);
viewHolder.textView.setText(text);
viewHolder.textView.setMovementMethod(LinkMovementMethod.getInstance());
This is a code which I am using to fill textView
I want in the end text looking like so:
Icons made by Freepik
I think you can't accomplish what you want in this way.
I think the simplest solution is to separate your links in differents list items. Keep in mind that you could use different TextView with different heights for example
Alternatively you could pass to a custom view approach. If you create a custom view (for example MultiLinkView), then you could add this view to the ListView.
I suggest this solution because this approach allow you to add a powerful logic to the view item.
I can't give you the complete code because it should be too long, but I can put you in the right way.
A custom view is a real Java class that extends some Android view class. So when you instantiate a CustomView you can pass to its constructor all the params you want (references, links, arrays and so on).
Start here
My idea is to find a way to pass all the parameters you need to your custom view and then find a way to represent your data, mapping them to your links.
I think you should abandon html solution in favor to ClickableSpan.
This is a piece of code that I used in a project to make clickable a single part of my string:
String text = "Hello <b>click me!</b> to go to internet!";
// create Spanned
Spanned spanned = Html.fromHtml(text);
// create SpannableString
SpannableString spanString = new SpannableString(spanned);
// set clickable part
ClickableSpan clickablePart = new ClickableSpan() {
#Override
public void onClick(View textView) {
if (connectionDetector.isConnectedToInternet()) {
// open browser or webview fragment
}
}
#Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(Color.WHITE);
}
};
int startClickMe = spanString.toString().indexOf(text);
spanString.setSpan(clickablePart, startClickMe, text.length() + startClickMe, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Obviously in the onClick you should find a way to get the right link, but, as I said before, in a custom view you can put as many variables as you want. I'm sure that you can find a solution.
Let me know if it helps
Hello I'm new to android developing.
Is there a method in java that equals to #.gotFocus?
Is there in java an events list that I can watch and select like in c# visual studio?
I tried to do #.Focus or something similar but had no success.
I want to reproduce the following scheme:
1- EditText has a certain hint => "Enter a value"
2- The user clicks the edit text and the hint disappears => ""
3- The user fills a certain value => "certain value"
Thank's for helpers :)
Ron Yamin, If I understand your doubt correctly what you want is:
1- Have a field of text for the user to type words/numbers etc --> It is called EditText in android
2- Have an hint so the user knows what to type --> Eg. "Type your name"
3- And react to focus in some way.
The first one you will achieve either through XML or by code. If you have a main.xml in your layouts folder (assuming you are using eclipse/android studio to develop), you can use the interface to drag an edit text to the android screen.
The second one you will achieve still through the XML. If you right click on it, right side of the screen there will be a little window called Proprieties that you can change things like height and width and a hint. Type there your hint.
Finally the last one you need to go to your code in .java and get a reference of your edit text (findViewById).
Either through setOnClickListener or setOnFocusChangeListener.
More info you can checkout here:
http://developer.android.com/guide/topics/ui/controls/text.html
I have googled a tutorial you can check with more detailed information and step by step guide.
Hope it helps:
http://examples.javacodegeeks.com/android/core/widget/edittext/android-edittext-example/
It seems that you changed your question quite a bit, and my C# ignorance got the best of me.
It seems that what you really want is an EditText, the example text you are looking for is the hint.
You can set the hint in the xml file or by code with .setHint(string) method.
Here's where to start:http://developer.android.com/guide/topics/ui/controls/text.html
edit 3 - events in android are dealt with by using listeners. You can use an onClickListener to achieve what you want.
textView.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(){
//dostuff
}
}
Assuming your textfield is an instance of EditText (which it probably should be), you can do the following:
textfield.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
// this is where you would put your equivalent #.gotFocus logic
}
}
});
It's worth noting that the behavior you've described can be achieved by using textfield.setHint. The hint is text that is cleared automatically when the user selects the EditText. It's designed specifically for the case you describe, e.g. textfield.setHint("Enter a Value")
I'm not familiar with c# but I'm guessing you want event fired when edittext get focus. Try this
EditText txtEdit= (EditText) findViewById(R.id.edittxt);
txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
// do the job here when edittext get focus
}
}
});
In my application I have a list of questions stored in an ArrayList, and I want to display a dialog that shows one question, and then continues to the next one after the question is answered. The way that I'm currently doing it (iterating through a loop) hasn't been working because it just layers all of the dialogs on top of one another all at once which causes a host of other issues. What I'm looking for is a way to still iterate through the questions, but just change the layout of the dialog each time until it has finished each question in the list. Can anyone give me a good pointer for how to get this going?
You can make a function that takes title and message as parameters and shows a dialog.
showDialog(String title, String message){ // Show dialog code here}
Within that dialog's answer button's listener call another function (showQuestion(currentQuestion)) that iterates the arrayList till it is over
int currentQuestion=0;
ArrayList<QuestionObject> questionList;
showQuestion(int i){
if(i<questionList.size()){
showDialog(questionList.get(i).getTitle,questionList.get(i).getMessage);
currentQuestion++;
}else{
//quiz is over
}
}
I assume you mean that you just want to change 1 single layout(created within XML i.e main.xml). In order to do this, make sure that the class your working on is pointing to that layout. From there (assuming your using an Event listener for when the user submits an answer) you can change do as you want by the following:
TextView txt = (TextView) findViewById(R.id.textView); // references the txt XML element
and in your Event listener, if the answer is correct then change(Have i be a global variable thats initially set to 0).
if(i<arrayList.size()){
txt.setText(arrayList.get(++i));
}else{
txt.setText("You Finished");
}
From there, in the else statement, you can change arrayLists and reset i to 0;
If you are trying to use the positive, neutral, and negative buttons; then you may have problems with multiple dialogs. Try defining a customized layout with your own TextViews, ListViews, and Buttons. You can implement listeners and everything else like a regular layout. Then just pass your customized layout to the dialog through AlertDialog.Builder.setView().
PS If you include code examples of what you are currently doing we can provided answers that are less vague.
Here is my problem: I am using AFreeChart to display a chart in my activity. The reason why I used AFreeChart was because I first finished this chart with JFreeChart, and, realized after that, it wasn't compatible with Android.
So, with AFreeChart, I could create the same chart with exactly the same code, but I don't know how to display it on a View.
Here I am creating the chart:
private void creerGraphique(){
//Here I have the creation of the DateSet
AFreeChart chart = ChartFactory.createXYLineChart(
"Mois", // Title
"Jours", // x-axis Label
"Repetitions", // y-axis Label
graph, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
true, // Use tooltips
false // Configure chart to generate URLs?
);
}
Here I want to use it:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graphique);
this.stockTableau();
this.creerGraphique();
//HERE: How can I display it since it's already created
}
I downloaded the AFreeChart demo code, but a function which wasn't on the package was used, and so, I couldn't use it too.
I thank you for your help.
PS: I'm not an english, so I hope my problem is clear, do not hesitate to ask me more details.
Have you looked at the sample in AFreeChart? It's quite straight forward, look at what they did for this chart for instance :
http://code.google.com/p/afreechart/source/browse/trunk/afreechart_sample/src/org/afree/chart/demo/view/PieChartDemo01View.java
They extend a DemoView which is basically an Android View with a setChart method, and pass the chart to the View.
So either extend DemoView or create you own equivalent if you don't need everything that's in it and follow the sample !
Good luck.
It is also worth noting that using the code you've pasted above, it would be helpful to call the chart's draw() method when you want it to draw.
As a simple example, if you were using a SurfaceView, you could create a method something like the following:
private void drawChart(AFreeChart chart, ChartRenderingInfo info) {
getHolder.lockCanvas();
chart.draw(canvas, area, info);
getHolder().unlockCanvasAndPost(canvas);
}
Where 'canvas' and 'area' have been set.
This is useful if you are looking to do a very simple implementation where you don't want to use the DemoView discussed above.