Question regarding Android Dev Studio (java) WebView - General Questions and Answers

Hi all
I have programmed my first app, a calculator using webview, i have one main question
When rotating the webview it did clear itself, i have solved this using the following code
protected void onSaveInstanceState(Bundle outState) {
Screen.saveState(outState);
outState.putString("editTextData1", edt1.getText().toString());
super.onSaveInstanceState(outState);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null)
{
((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
}
Click to expand...
Click to collapse
However the cursor for my calculator moves back to the start of the webview upon rotation and hence when i type it deletes the existing sum from before the rotation, please help

Related

[Q] Android full screen menus

My question is relatively simple; is the code below an accepted method of changing full screen menus in Android 2.1? I thought I should ask, because when I switch back using the back key without doing the findViewById again, the menu doesn't work. So I have to reconstruct the menu each time (createMainMenu() method). To implement the back key I use a state, which is dependant upon which menu the system is in.
Also, I thought using multiple activities was not necessary in this small application.
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
createMainMenu();
}
private void createMainMenu(){
setContentView(R.layout.main);
state=STATE_MAIN;
createKeyButton=(Button)findViewById(R.id.createKeyButton);
encryptTextButton=(Button)findViewById(R.id.encryptTextButton);
decryptTextButton=(Button)findViewById(R.id.decryptTextButton);
createKeyButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
createKeyCreationMenu();
}
});
}
private void createKeyCreationMenu(){
setContentView(R.layout.create_key);
state=STATE_MENU;
keyLengthField=(EditText)findViewById(R.id.keySizeEditText);
}
public void onBackPressed(){
if(state==STATE_MENU){
createMainMenu();
} else if(state==STATE_MAIN){
super.onBackPressed();
}
return;
}
SOLVED
Although this method works, you get problems when the user turns the screen. I have resolved to launching new activities for new full screen menu's.
Can a moderator please move this thread to the android software forum?

[Q] developping in android issue

hello,
I am learning to develop on android and I have an issue. I hope this is the right place to find help. I tried the development forum but apparently I can't post there.
So here is my issue:
I'm trying to create a header for my application. In this header, I have a button, and since I don't want to duplicate my button click handler in every activity, I created a MotherActivity (that inherits Activity) from which my activities will inherit from.
In my first activity, I wrote:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myActivity1); (myActivity1 <includes> layout.header)
}
and in my MotherActivity, I used:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout include_header = (LinearLayout)(findViewById(R.layout.header));
((ImageView)( include_header.findViewById(R.id.ImageButton1)))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something
}
});
}
My problem is that findViewById(R.layout.header) returns null.
If I try to invert onCreate() and setContentView(), I receive this error:
ERROR/AndroidRuntime(872): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
So I don't know what to do, in both cases I receive an error...
Can you help me please ?
Thanks.
I managed to fix the error.
But there's something I don't understand. The whole point of this architecture with an inherited activity was to create a button in the header, and whose event handler wouldn't need to be rewritten in all the activities.
But the button doesn't do anything when clicked on.
How is that possible ?

calling picasa web album data api

I am new bee trying to play with android sdk , I started with helloworld , next I am trying to use google picasa web api in sample app ,
here is my code
Code:
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
setContentView(R.layout.main);
Button btn1 = (Button)findViewById(R.id.btnClickMe);
btn1.setOnClickListener(btnListener);
}
private OnClickListener btnListener = new OnClickListener()
{
public void onClick(View v)
{
try{
PicasawebService myService = new PicasawebService("exampleCo-exampleApp-1");
myService.setUserCredentials("[email protected]", "mypassword");
URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/myusername/albumid/myalbum");
AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);
for(PhotoEntry photo : feed.getPhotoEntries()) {
System.out.println(photo.getTitle().getPlainText());
}
}catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
in onclick listner I am calling google api , whne the application is started and when I click the button I get unfortunately Helloandorid has stopped , no mexception nothing. Please advice me can I use google api in adroid app ?

[Q] setText error

Hi, I'm new to android programming. i just started with hello world then change the textview from java. When I use the setext, app stopped working. Anyone pls help
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView mTextView = (TextView) findViewById(R.id.textView1);
mTextView.setText("Some Text");
setContentView(R.layout.activity_main);
}
I don't know what's wrong in that. Just today i downloaded the adt bundle and API 18.
you gotta set your contentview first.
read this thread for future problems.
http://forum.xda-developers.com/showthread.php?t=2325164

Popup box Help

So i have created a pop up window with the source code below. I also have designed the popup really good. and it displays right. The only problem i have is the damn button to close it. lol I had it so it closed fine before. Then i started adding stuff in to make the app work the way i want it to.
So What i have done is this, I have the popup created i want to be able to have the Text box checked for a string if this string exists then I need to go to thread allApps which then launches my 2nd Activity which that works fine as well. But the problem is the damn pop uup is still up so i need to close this. Any way of doing this with using the code I have or do i need to redo something. Please Any help thanks
PHP:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
final Button btnOpenPopup = (Button)findViewById(R.id.apps_button);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(btnOpenPopup, Gravity.CENTER, 0, 0);
}});
}
public void allApps(View arg)
{
Intent intent = new Intent(arg.getContext(), AppList.class);
startActivity(intent);
}

Categories

Resources