[Q] Reinsert Text to TextView - Java for Android App Development

Hi everyone .
Can I combine to Texts into one TextView ?
I know its very ununderstandable . So let's shape it :
Imagine I have to Buttons That navigates to two different activities which both Have one view , one code but different texts .
Now imagine I have 1hunderd of them .
Can I make just one activity with one TextView item but the texts inside it differs depending on choosing different buttons ? If not understandable again let me know please .
Thanks in advanced

Yeah, you can:
When the button is clicked, do something like this:
Code:
TextView tv = (TextView) findViewById(R.id.[id of the text view]);
tv.setText([either the resource id or the text]);
You can check which text is displayed using the getText() method of the TextView and then display the other text using the method I gave you above. :good:

Related

[Q] Item separator in ListView fails! TextSize is the reason?

As you can see in this screenshoot ( ht tp://yfrog.com/myselezione002p ) ListView doesn't show all item separator, seems that the problem is setting textSize for TextView. (I have already tried with ListActivity instead of Activity, but same result)
This is a little testcase:
ht tp://pastie.org/1218668
Thanks for any response!

Collada Loader

I would like to point out that the example at google code of a Collada Loader is misleading. (code.google.com/p/androidcolladaloader)
The way to handle data in the characters(char[] ch, int start, int length) callback funtion should be done in the endElement(String uri, String localName, String name) callback function. This is because data between XML tags can be splitted by the sax xml parser and then call the characters function multiple times. The solution to this I found at coderanch:
coderanch.com/t/432967/XML/Missing-characters-SAX-Parser
Where Ulf Dittmer suggests:
Yes. The one you have apparently assumes that all text data is returned in a single chunk (I can't tell for sure since you didn't post the full code of the method). You need to change it so that it still works if the text is returned in several chunks. One way to do that would be to append the text to a StringBuffer (which would be field in your handler class). Once the end element of whatever tag surrounds this text is reached, you can handle the text itself.
Click to expand...
Click to collapse
An example of working with a stringBuffer in the characters function is shown here:
onjava.com/pub/a/onjava/2002/06/26/xml.html?page=2
Note that the start and length argument given with the characters call back function are not there for nothing!

[Q] app crashes whenever call is made to change the content viewthe

whenever I use
Code:
tv.setText("Game Over!"); setContentView(tv);
my program crashes (note: tv is an object of the TextView class)
Before this call is made the program is set to a default view that contains a text view, buttons, etc. But the crash only happens when I call the method to change the view. Any ideas?
You probably wouldnt wanna do setContentView on a textview, unless its the only thing you want on the screen. Are you creating the textview dynamically? (In the java code) Or is this a textview you create in the xml. If you are doing it dynamically, are you giving it LayoutParams first?
Yes its dynamic. What kind of LayoutParams do you mean?
Sent from my GT-I9000M using XDA App
If you just create a new textview...
TextView text = new TextView(context);
its just floating around not attached to anything. Just create a quick layout with a textview in it, and do
setContentView(R.layout.layout2);
or you could try
tv.setLayoutParams(new LayoutParams(LayoutParam.WRAP_CONTENT,LayoutParam.WRAP_CONTENT));
It still crashes, no matter what I do as soon as I try to do anything with the TextView tv, it crashes
setting it works: final TextView tv = (TextView) findViewById(R.id.stats);
But doing ANYTHING with tv crashes.
Examples:
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams. WRAP_CONTENT));
tv.setText("testing");
Anything I'm overlooking?
Well for starters you cant change anything about a variable that you declare as final..

Adding Bookmarks Are Invisible?

So, I wrote this block of code:
Code:
ContentValues values = new ContentValues();
values.put(BookmarkColumns.BOOKMARK, "1");
values.put(BookmarkColumns.CREATED, "1311170108");
values.put(BookmarkColumns.DATE, "1311170708");
values.put(BookmarkColumns.FAVICON, "favicon");
values.put(BookmarkColumns.TITLE, "XDA");
values.put(BookmarkColumns.URL, "http://forum.xda-developers.com");
values.put(BookmarkColumns.VISITS, "1");
getContentResolver().insert(Browser.BOOKMARKS_URI, values);
When executed, I get no errors. Looking in the browser bookmarks section, the book mark is not there. If i click the Most Visited tab, this shows up and also has the yellow bookmark star next to it, indicating that it is a bookmark. If i click the star to unbook mark it, and click it again, then view the Bookmarks tab, it shows up.
If I use another piece of code to print out all the bookmarks found after I add it, mine shows up
Even with rebooting, they are not showing.
So I ask, why is it that they are not showing up in the bookmarks page of the browser?
I have tried everything and looked around everywhere, and nothing
Thanks!
there is no sanctioned way of adding a bookmark without user input. the normal way would be a call to android.provider.Browser.saveBookmark()
Code:
public static final void saveBookmark(Context c, String title, String url) {
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
}
other than that dealing with the DB directly would be the only way to add one. try to follow that startActivity to the dialog and see if there is an intent sent to the Browser telling it the DB was updated
killersnowman said:
there is no sanctioned way of adding a bookmark without user input. the normal way would be a call to android.provider.Browser.saveBookmark()
Code:
public static final void saveBookmark(Context c, String title, String url) {
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
}
other than that dealing with the DB directly would be the only way to add one. try to follow that startActivity to the dialog and see if there is an intent sent to the Browser telling it the DB was updated
Click to expand...
Click to collapse
But, even with restarting the device the book marks are not there. Surely the browser updates the database at that point.
But it also dosnt make sense because if the page was shown in the history, it has the bookmarked indicator next to it
I must do all of this in a fully transparent way. Showing that popup for each one will not do :/
there are a few other columns that are interesting. 'user_entered' which can be '0' or '1'
But I think your best bet is to find the dialog that saveBookmark() calls and analyze its src
Here it is addBookmark()
http://www.java2s.com/Open-Source/A...rowser/com/android/browser/Bookmarks.java.htm
It appears to be static. Why not just call this method?
static void addBookmark(Context context, ContentResolver cr, String url, String name, Bitmap thumbnail, boolean retainIcon)
------nvm i think its package restricted
From something awesome

[Q] Need Help with a problem

I am using one edit text view and one OK button to input a large amount of user data during a setup function but can't figure out how to pause the thread execution unit the OK button is pressed. I don't want to have to register and use a ton of different buttons and listeners to call individual functions for each user input and so far I've found out the hard way that a while look will lock the UI thread and running the loop in a separate thread will not make the program wait. Any Ideas?
public class SetupMenuActivity extends Activity
{
private TextView setupPrompt;
boolean okButtonPressed = false;
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_menu);
setup();
}
private OnClickListener okButtonListener = new OnClickListener()
{
@override
public void onClick(View v)
{
okButtonPressed = true;
}
};
private void setup()
{
Button okButton = (Button) findViewById(R.id.okButton);
okButton.setOnClickListener(okButtonListener);
setupPrompt = (TextView) findViewById(R.id.setupPrompt);
setupPrompt.setText("Please Enter Your Name");
// Make program wait for ok button clicked
setupPrompt.setText("Please Enter a Name for your Account");
}
}
What else could the user click/etc that you want to prevent from happening? If you want to block another button, then you can either do button.setClickable(false) or even button.setVisibility(View.GONE) until the ok button is clicked. Instead blocking the whole thread doesn't make much sense
The only two things the user can interact with is the button and the edit text box. I want to prevent the changing of the setupPrompt text view until the Ok button is pressed. The easy way to do it would be to put it into the onClickListener but there is a whole series of the prompts and waiting for user input so I'm trying to avoid creating a ton of different button listeners for each piece of user input.
TShipman1981 said:
The only two things the user can interact with is the button and the edit text box. I want to prevent the changing of the setupPrompt text view until the Ok button is pressed. The easy way to do it would be to put it into the onClickListener but there is a whole series of the prompts and waiting for user input so I'm trying to avoid creating a ton of different button listeners for each piece of user input.
Click to expand...
Click to collapse
The way you think this would work is not right, you have to think through it again, sorry . In Android, you can almost never wait for user events (because they might not happen). Instead, you have to do what you can during setup and everything that can only happen after a certain event has to be in the onEvent method (for instance onClick). What you can do to make it less complex is one method which is called only from the onClickListener. The method keeps track of how many times it has been called with an int step instance variable. That method has to execute what should happen at each step.
SimplicityApks said:
The way you think this would work is not right, you have to think through it again, sorry . In Android, you can almost never wait for user events (because they might not happen). Instead, you have to do what you can during setup and everything that can only happen after a certain event has to be in the onEvent method (for instance onClick). What you can do to make it less complex is one method which is called only from the onClickListener. The method keeps track of how many times it has been called with an int step instance variable. That method has to execute what should happen at each step.
Click to expand...
Click to collapse
Yeah Agreed with Simp. I would honestly make one method with all the info you need then get all the info and call it only when the button is clicked. If I knew a bit more of what your trying to accomplish I might be able to help you code it more efficiently.

Categories

Resources