I have some text views in an linear layout in my android application. Next to them I want to put a small question mark of the form [?], that when tapped displays a popup with some information. I could do this with a button but it would be very big.
Is there any simple way of doing this?
You could set the question mark in a new TextView, and set a click listener via the onClickListener(View.OnClickListener l). From there you could use the getId() method to determine the question mark that was called. Then, you could use a switch statement, to split your programflow, and to whatever you want inside the switch statement.
TextView in the Android Reference:
http://developer.android.com/reference/android/widget/TextView.html
You could use a TextView with the text ?.
set the width to wrap_content
handle the onClick event to open the popup
use TextView to show ? and use PopupWindow for showing message as on textview click :
TextView t = (TextView)findViewById(R.id.TextView01);
t.setOnClickListener(this);
}
public void onClick(View arg0) {
// OPEN PopupWindow HERE
}
and how we create popupwindow you can see this tutorial for help:
Example of using PopupWindow
Related
I want to make a custom control in Android.
Actually, I want to extends a EditText with one Button and one TextView. (Like below picture)
My Custom Control Picture
I have not problem with listener. I want just make a custom control that contains 3 controls. (EditText, Button and TextView)
How can I do it?
Create a Linear layout with orientation = horizontal .
Then create an edittext and a button in it .
In java code ,set onClicklistener on button and then get the value of edittext by [edittext].getText().toString() ;
Control means you want to perform any action (a similar action i understand from your explaination) on click of any of the three?
If so, have a specific method which will be called on click of each of the items and alter them according to your choice.
Is this what you meant by user control?
I know how to read an excel sheet in android, but now I want to put the data from that excel sheet into the text box by clicking a button. I did this after reading the excel sheet.But unformatted symbols are on the text box when i clicked the button.I just want to display the data on the excel sheet on the text box.I searched this every where but I didn't find. Can I do this? If so how?
(I used jxl.jar to read the excel sheet.)
If you know how to get the data from your excel sheet, it is quite simple to put it into a TextView when a Button is clicked.
First, cast your Button. This means linking the button from your layout to the one in your code. Do so like this;
Button myButton = (Button) findViewById(R.id.MY_BUTTON);
Of course, you can change the name from myButton to whatever you like (but it must remain the same name throughout), and MY_BUTTON must be the same id as the button in your layout.
Next, you set an OnClickListener. This listens out for when the button is clicked, as the name indicates. In your OnClickListener, you will cast your TextView (almost the same as what we did with the button, but for a different thing), and set the text to it. See below:
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView myText = (TextView) findViewById(R.id.MY_TEXTVIEW);
// Again, 'myText' can be changed to what you want - it needs to be the same consistently
// and 'MY_TEXTVIEW' must be the same id as the one in your layout XML file
// Now, we set the text to your data
myText.setText(YOUR_DATA);
// 'YOUR_DATA' is the data that you want to display in the TextView
}
});
I wanted to develop an on screen keyboard similar to the square app (image below)
I would appreciate it if anyone could give me tips on which classes to focus on/ override for this. In particular, how do I associate the button clicks to the number input in the EditText field?
Every Button gets a Tag with the associate value (for example 1). Then, you use the android:onClick-attribute to set all buttons to the same method (input() for example) in the activity.
This method will be called with the clicked view, which you can then use the getTag()-method on to get the corresponding value:
// Will be called for every Button that is clicked
public void input(View v){
Log.v("APP", "Pressed: "+v.getTag());
}
Organize the Buttons in a GridLayout (GridView might also be possible).
So basically I have an Activity with a layout that shows my custom SurfaceView and an invisible EditText.
How can I call setVisibility(VISIBLE) on that object? I do use post(Runnable...) on my SurfaceView object, but the problem is findViewById(my EditText id) returns null?
I found why but how do I solve it?
Also, how do I recive a callback from the "Done" button on the EditText? Is it the same as the enter key?
You need to search for id.content on the view that has it as a child. So use the following:
TextView t = (TextView) getParent().findViewById(R.id.contents);
To answer your other question, to find when the user hits the enter key, use
t.setOnEditorActionListener(...)
I have an image button which says Select city I want to call an android spinner if anyone clicks on that image. Is it possible??
I would recommend you check out the App/Alert Dialogs section of the API Demos application. I think what you are looking for is a dialog with a single choice list.
Or take a look at this:
http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList
This is entirely possible in several ways. One way is to have a spinner whose visibility is GONE. Clicking on the image makes the spinners visibility VISIBLE.
Another choice is to create a dialog that has the spinner and use the selection to do whatever it is you want to do.
There are other options, but that should get you started.
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mySpinner.performClick();
}
});