How to click or tap on a TextView text - android

I know this is so easy (doh...) but I am looking for a way to run a method on tapping or clicking a TextView line of text in an Android App.
I keep thinking about button listeners and anonymous method listener calls, but it just does not seem to apply to TextView.
Can someone point me at some code snippet to show how clicking or tapping on a piece of text in a TextView runs a method?

You can set the click handler in xml with these attribute:
android:onClick="onClick"
android:clickable="true"
Don't forget the clickable attribute, without it, the click handler isn't called.
main.xml
...
<TextView
android:id="#+id/click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:textSize="55sp"
android:onClick="onClick"
android:clickable="true"/>
...
MyActivity.java
public class MyActivity extends Activity {
public void onClick(View v) {
...
}
}

This may not be quite what you are looking for but this is what worked for what I'm doing. All of this is after my onCreate:
boilingpointK = (TextView) findViewById(R.id.boilingpointK);
boilingpointK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if ("Boiling Point K".equals(boilingpointK.getText().toString()))
boilingpointK.setText("2792");
else if ("2792".equals(boilingpointK.getText().toString()))
boilingpointK.setText("Boiling Point K");
}
});

OK I have answered my own question (but is it the best way?)
This is how to run a method when you click or tap on some text in a TextView:
package com.textviewy;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class TextyView extends Activity implements OnClickListener {
TextView t ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = (TextView)findViewById(R.id.TextView01);
t.setOnClickListener(this);
}
public void onClick(View arg0) {
t.setText("My text on click");
}
}
and my main.xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="#+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout>
<ListView android:id="#+id/ListView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>
<LinearLayout android:id="#+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout>
<TextView android:text="This is my first text"
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:textStyle="bold"
android:textSize="28dip"
android:editable = "true"
android:clickable="true"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>

from inside an activity that calls a layout and a textview, this click listener works:
setContentView(R.layout.your_layout);
TextView tvGmail = (TextView) findViewById(R.id.tvGmail);
String TAG = "yourLogCatTag";
tvGmail.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View viewIn) {
try {
Log.d(TAG,"GMAIL account selected");
} catch (Exception except) {
Log.e(TAG,"Ooops GMAIL account selection problem "+except.getMessage());
}
}
});
the text view is declared like this (default wizard):
<TextView
android:id="#+id/tvGmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/menu_id_google"
android:textSize="30sp" />
and in the strings.xml file
<string name="menu_id_google">Google ID (Gmail)</string>

Although you can resolve the problem by setting the listener to textview, it's recommended not to. You should use flat button as it is a subclass of Button and it provides many attributes which TextView doesn't.
To use flat button, add style="?android:attr/borderlessButtonStyle" attribute -
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DONE"
style="?android:attr/borderlessButtonStyle"/>

in textView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:onClick="onClick"
android:clickable="true"
You must also implement View.OnClickListener and in On Click method can use intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://youraddress.com"));
startActivity(intent);
I tested this solution works fine.

To click on a piece of the text (not the whole TextView), you can use Html or Linkify (both create links that open urls, though, not a callback in the app).
Linkify
Use a string resource like:
<string name="links">Here is a link: http://www.stackoverflow.com</string>
Then in a textview:
TextView textView = ...
textView.setText(R.string.links);
Linkify.addLinks(textView, Linkify.ALL);
Html
Using Html.fromHtml:
<string name="html">Here you can put html <a href="http://www.stackoverflow.com">Link!</></string>
Then in your textview:
textView.setText(Html.fromHtml(getString(R.string.html)));

You can use TextWatcher for TextView, is more flexible than ClickLinstener (not best or worse, only more one way).
holder.bt_foo_ex.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// code during!
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// code before!
}
#Override
public void afterTextChanged(Editable s) {
// code after!
}
});

Related

How to make a TextView Clickable with a extra ID in android

I am developing a Android Application, where i have multiple textView and I want those textview clickable. When I will click those textView I will get a common empty form but with a static ID in the top for every textview.
For example: If I have 3 product name in 3 text view, if I click on textView1, a previously made layout will be shown and there will be a static ID with my product name in the top, then there will be form to filling up the details of the product.If I click on the textView2 then the form will be same only the Static ID and the product name will change.
I hope you guys understood what I wanted to explain.
I am new in application development so I need some simple solution.
So far I have made a layout of my form and I have also made a clickable Layout. So I need to know how I would make the class and function to call the layout and plus the static ID.
Layout of the product name and the Clickable TextView:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/p85"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
android:textStyle="bold"
android:layout_marginTop="12dp"
android:text="#string/p85"
android:ems="7"
android:textSize="35sp"
android:textColor="#375C34"
android:clickable="true"
android:background="#drawable/product_list_view"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</ScrollView>
ProductList.java file that call the product_list.xml
import android.app.Activity;
import android.os.Bundle;
public class ProductList extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.product_list);
}
}
In xml in your textview put :
android:onClick="onClick"
And have this
public void onClick(View v) {
switch(v.getId()){
case R.id.TextViewFromXml):
// do something
break;
}
}
Or Remove this
Textview.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
First set Tag(i.e your Static ID) to TextView and then set Clicklistner
tv.setTag("1234");
tv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
myId=tv.getTag();
}
});

Android RelativeLayout - show items side by side when space but on separate lines when insufficient space?

I'm laying out an app which presents the results of a search in a ListView. I've defined each item to have a custom layout as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="5dp"
android:paddingRight="?android:attr/scrollbarSize" >
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSearchResultTitle"
android:textIsSelectable="false" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/title"
android:layout_toRightOf="#+id/subtitle"
android:gravity="bottom|right"
android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle"
android:textIsSelectable="false" />
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/title"
android:gravity="bottom|left"
android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle"
android:textIsSelectable="false" />
</RelativeLayout>
This looks great when subtitle and date are of appropriate length to fit on a single line, however it looks awful if the subtitle consumes most of the line and forces date to take a very thin width and so wrap vertically.
What I'd like to do is have them appear side-by-side when there's space but on separate lines if there isn't. I've tried fiddling with the various layout_* attributes and the gravity to no avail and the question isn't very Google-able (at least, I can't think of the right words to search for). Can anyone point me towards the combination of layout rules that I need to achieve this? Or perhaps a different container if one would be more appropriate?
I believe the code below will do what you want but I can't see a way to do this only in the xml layout.
Basically I have added a textChangedListener to two different TextViews that have the two different layout options I believe you are looking for, both inside their own relative layout with the date displaying textview. When the subtitle is set the first of these is used to hold the text, if it requires more than a single line the second TextView is used and in either case the other has its visibility option set to GONE.
In my example I use a seperate thread to change the subtitle, hopefully this doesn't confuse things too much.
The layout xml is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSearchResultTitle"
android:background="#FF009999"
android:textIsSelectable="false"
android:text="#string/my_title" />
<RelativeLayout
android:id="#+id/resizingTextContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title" >
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle"
android:textIsSelectable="false"
android:textColor="#FFFFFFFF"
android:background="#FF000000" />
<TextView
android:id="#+id/subtitle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/date"
android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle"
android:textIsSelectable="false"
android:textColor="#FFFFFF"
android:background="#FF00FF00" />
<TextView
android:id="#+id/subtitle2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/date"
android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle"
android:textIsSelectable="false"
android:visibility="gone"
android:textColor="#FFFFFF"
android:background="#FF00FF00" />
</RelativeLayout>
<Button
android:id="#+id/startTestBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/resizingTextContainer"
android:layout_centerHorizontal="true"
android:text="Click To Begin"
/>
</RelativeLayout>
And the main activity code with the textview switching logic:
package com.example.code.examples.changelayoutwithtextlength;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
TextWatcher textChangeDisplayCheck = new TextWatcher(){
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
displayLatestSubtitle(s);
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView DateTextView = (TextView)findViewById(R.id.date);
DateTextView.setText("29th April 2013");
Button b = (Button)findViewById(R.id.startTestBtn);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
v.setEnabled(false);
Thread thread = new testSubtitleThread();
thread.start();
}
});
TextView tv = (TextView)findViewById(R.id.subtitle1);
tv.addTextChangedListener(textChangeDisplayCheck);
TextView tv2 = (TextView)findViewById(R.id.subtitle2);
tv2.addTextChangedListener(textChangeDisplayCheck);
}
private void displayLatestSubtitle(CharSequence newSubtitle)
{
TextView tv = (TextView)findViewById(R.id.subtitle1);
TextView tv2 = (TextView)findViewById(R.id.subtitle2);
tv.removeTextChangedListener(textChangeDisplayCheck);
tv2.removeTextChangedListener(textChangeDisplayCheck);
tv.setVisibility(View.GONE);
tv2.setVisibility(View.GONE);
tv2.setText("");
tv.setText(newSubtitle);
if(tv.getLineCount() > 1)
{
tv.setText("");
tv2.setText(newSubtitle);
tv2.setVisibility(View.VISIBLE);
}
else
{
tv.setVisibility(View.VISIBLE);
}
tv.addTextChangedListener(textChangeDisplayCheck);
tv2.addTextChangedListener(textChangeDisplayCheck);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class testSubtitleThread extends Thread
{
String[] subtitles = new String[] { "a short one", "a really long winded subtitle that will take over more than the allowed space", "tiny",
"Really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, long.",
".....", "text just to long to fit on my device"};
private android.os.Handler handler = new android.os.Handler()
{
#Override
public void handleMessage(android.os.Message msg)
{
if(msg.what < subtitles.length)
{
TextView tv = (TextView)findViewById(R.id.subtitle1);
tv.setText(subtitles[msg.what]);
}
else
{
Button b = (Button)findViewById(R.id.startTestBtn);
b.setEnabled(true);
}
}
};
#Override
public void run()
{
for(int i = 0; i <= subtitles.length; i++)
{
handler.sendEmptyMessage(i);
try
{
Thread.sleep(3000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
I hope this helps.
In your layout, I would define two Views per item (subtitle and date), one in the same line and one in the line below.
Then I would check the length of those 2 fields (or their sum) and I would write this piece of code:
if (length > MAX_LENGTH_OF_LINE) > {
findViewById(R.id.subtitle_line_below).setVisibility(View.VISIBLE);
findViewById(R.id.subtitle_same_line).setVisibility(View.GONE);
} else {
findViewById(R.id.subtitle_line_below).setVisibility(View.GONE);
findViewById(R.id.subtitle_same_line).setVisibility(View.VISIBLE);
}

how to click on textview in android

Click on text view is not working
My xml is
<TextView
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="3"
android:gravity="center"
android:textColor="#color/white"
android:text="click to download sevenstepstocollege"
android:textSize="15dp"
android:onClick="downloadLink"
android:clickable="true">
</TextView>
and My Activity code is
public void downloadLink(View v)
{
//String requestId = PurchasingManager.initiatePurchaseRequest(skuKye);
//String requestId=PurchasingManager.initiateItemDataRequest("DeveloperSKU-1234");
skuSet.add(skuKye);
final String requestId = PurchasingManager.initiateItemDataRequest(skuSet);
}
But it is not working.I am not able to click that link.please guide me
Well, I use the following code to make a TextView clickable.
First, add this at your activity.xml, to make TextView clikable:
<TextView
android:id=android:id="#+id/button2" <!-- id to get this TextView -->
(...)
android:onClick="onClick" <!-- Add the function onClick() -->
android:clickable="true" <!-- Set the boolean clickable to true -->
/>
Then, at your MainActivity.java, you add:
private TextView textview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the TextView by id
textview = (TextView) findViewById(R.id.button2);
textview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO when clicked on your link(TextView)
}
});
}
As I see now that you are trying to make a link from the TextView clickable, not just be able to click on the TextView I will let a link below to a similar question solved in Stack Overflow that you might find helpful.
The android developer reference to TextView:
https://developer.android.com/reference/android/widget/TextView.html
The similar question in Stack Overflow about how to make a links in a clickable that might be helpful:
How do I make links in a TextView clickable?
You may use like this
<TextView
android:id="#+id/topPaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:clickable="true"
android:text="#string/topPaid"
android:textColor="#000000"
android:textColorLink="#33CC33" />
and At activity
TextView topPaid = (TextView) findViewById(R.id.topPaid);
Linkify.addLinks(topPaid, Linkify.ALL);
topPaid.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//write ur logic
}
}
TextView textview = (TextView) findViewById(R.id.text);
textview.setText(Html.fromHtml("<b>Text:</b> Text with a " + "link " + "Created in the Java source code using HTML."));
XML Code
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
JAVA Code
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(Html.fromHtml("google "));
textView.setMovementMethod(LinkMovementMethod.getInstance());
In your XML as the following:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onTextViewPressed"
/>
In your attached activity
public void onTextViewPressed(View view) {
...
}

android -- make calculations with input data (numeric) -- (show graphs?)

I am starting to learn android and i have a few questions.
I have my main program as:
public class Radiation_overflowActivity extends Activity implements OnClickListener {
EditText init_cores;
View final_cores;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Set up click listeners
init_cores=(EditText) findViewById(R.id.init_cores);
//init_cores.setOnClickListener(this);
final_cores=(View) findViewById(R.id.final_cores);
final_cores.setOnClickListener(this);
}
//called when a button is clicked
public void onClick(View v) {
switch (v.getId()){
case R.id.final_cores:
//int r = Integer.parseInt(init_cores.getText().toString().trim());
double initcores=Double.parseDouble(init_cores.getText().toString().trim());
double l=2,t=2;
double fcores=initcores*Math.exp(-l*t);
Intent i=new Intent(this,calcs.class);
i.putExtra("value",fcores);
startActivity(i);
break;
}
}
}
Also, my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/initial_cores" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/init_cores"
android:inputType="numberDecimal" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/final_cores"
android:text="#string/calculate" />
</LinearLayout>
My calcs.java:
public class calcs extends Activity{
TextView calcs_final;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calcs);
calcs_final=(TextView) findViewById(R.id.calcs_final);
double f=getIntent().getExtras().getDouble("value");
calcs_final.setText(Double.toString(f));
}
}
My calcs.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/calcs_final"
android:text="#string/result" />
</LinearLayout>
I want to do this:
The user enters data into the edittext (init_cores) and then i want to make some calculations to compute the final_cores and show it to the user.
I have trouble for showing the results.I am starting another activity (calcs.class and calcs.xml).
Where i must do the calculations?To the calcs.class?
Right now,the user enters a number ,presses the "Calculate" button and then it shows the text (from the strings.xml) "Number of cores"" ,but not the result.
Also, can i use the input from the data and from my calculations and make a plot?If you could give me some directions to this.
Finally,is my approach right?
Thank you!
For plotting your data, you can use the AChartEngine library, which is quite extensive and easy to use.
As per I think your final_cores is a view on which, you want to get your edittext's value for calculation(Hope I am not wrong)
So, just do Something like,
public void OnClick(View v) {
switch (v.getId()){
case R.id.final_cores:
int r = Integer.parseInt(init_cores.getText().toString().trim());
Intent i=new Intent(this,calcs.class);
i.putExtra("value",r);
startActivity(i);
break;
}
}
Remove onClickListener from your init_cores edittext. And get values of r in your Calcs.class using
int r = getIntent().getExtras().getInt("value");
Also be sure in your edit text always you are entering numeric values so it can be parsable into Integer..
Try this and let me know what happen..
Thanks,

Android - change textView at run time

I´m working with a lineal layout and I´m trying to change the text of a TextView but it doesn´t refresh. When I debug I´ve checked that the text have changed correctly.
Thanks
public class Position extends Activity {
Button botonempezar;
Button botonsalir;
TextView text;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.position);
botonsalir = (Button) findViewById(R.id.salir);
botonempezar = (Button) findViewById(R.id.Empezar);
text = (TextView) findViewById(R.id.Textoposicion);
botonsalir.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
onDestroy();
finish();
}
});
botonempezar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
searchPosition();
}
});
}
private void searchPosition(){
boolean condition = true;
do{
determinatePosition();
}while(condition == true);
}
private void determinatePosition(){
....
this.text.setText("New text");
//this.text.invalidate();
this.text.postInvalidate();
Toast.makeText(getBaseContext(), "New text", Toast.LENGTH_SHORT);// this doesnt work neither.
....
}
Here I post the code of the xml file. Its really silly but it could be the problem:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_height="wrap_content"
android:id="#+id/Textoposicion"
android:text="Posición desconocida"
android:layout_width="fill_parent"
android:layout_marginTop="20dip"
android:inputType="text">
</TextView>
<Button android:layout_height="wrap_content"
android:id="#+id/Empezar" android:text="Empezar"
android:layout_width="fill_parent"
android:layout_marginTop="20dip">
</Button>
<Button
android:layout_height="wrap_content"
android:id="#+id/salir"
android:layout_marginTop="20dip"
android:text="Finalizar programa"
android:gravity="center" android:layout_width="fill_parent">
</Button>
</LinearLayout>
I have edited the post because I omitted part of the code to make it simpler but I think I may suppressed the problem too. It runs in a endless loop, could be this the mistake?
Try to call invalidate on the view.
http://developer.android.com/reference/android/view/View.html#invalidate()
this.text.invalidate();
This will cause a redraw.
Sorry, too quick, I saw that you already tried that.
Didn't that work? Why did you comment that away?
You forgot to call show() method on Toast :). Try this:
Toast.makeText(getBaseContext(), "New text", Toast.LENGTH_SHORT).show();
Try not using getBaseContext(). Use Position.this
Well now your infinite loop is caused by
private void searchPosition(){
boolean condition = true;
do{
determinatePosition();
}while(condition == true);
}
Try moving the toast into public void onClick(View v)
Also, show us your imports

Categories

Resources