How do i create the above view in my android application? - java

Because i'm create an app similar to what was shown below but i have no idea how to create a view similar to what was shown above after i click a buttton to navigate to this page where all the video and map log file is shown..
I'm kinna new in android/java can someone guide me on this?
EDIT: This is a series of code for creating a directory to store my video files but these files can only be seen outside the application but i wanted it to be seen in the application where when a button is pressed it navigates to the VideoList to browse the various videa file i have filmed and when press it display a custom screen seen here. But what are the things should be done to achieve this?
File dirlist = new File(Environment.getExternalStorageDirectory() + "/VideoList");
if(!(dirlist.exists()))
dirlist.mkdir();
File TempFile = new File(Environment.getExternalStorageDirectory() + "/VideoList", dateFormat.format(date) + fileFormat);
mediaRecorder.setOutputFile(TempFile.getPath());

Hay Zack its a custom Dialog check out this... code
main.xml(Your main page layout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is my main activity, from here, I want to display a dialog, after the user clicked the button below this text.">
</TextView>
<Button android:layout_height="wrap_content"
android:layout_below="#+id/TextView01"
android:layout_width="wrap_content"
android:id="#+id/Button01main"
android:text="Hey! There is more..."></Button>
</RelativeLayout>
maindialog.xml(Your Dialog layout page)
<?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="wrap_content">
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="wrap_content" android:layout_below="#+id/ImageView01"
android:layout_height="200px">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</ScrollView>
<Button android:id="#+id/Button01" android:layout_below="#id/ScrollView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:text="Cancel" />
</RelativeLayout>
dilo.java(Display dialog on click button code)
package com.example.dilo;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class dilo extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1main = (Button) findViewById(R.id.Button01main);
button1main.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//set up dialog
final Dialog dialog = new Dialog(dilo.this);
dialog.setContentView(R.layout.maindialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
//set up text
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText(R.string.lots_of_text);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.icon);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
});
}
}
i think it should help you .... ok... N joy

zack it is custom dialog u need to create custom dialog
for more info.. go this link 1) link 2

Related

How do I implement a popup media player in Android for an mp3 file?

I have made an app that has 20 or so mp3 files in the res\raw folder, and when a button is pressed, the media is played, the button can then be pressed again and the media is stopped.
This works well, but it does not look very nice, ideally, what I would like is a little popup player that appears in the centre of the screen with a seek bar, a pause button, and the name of the song that plays. (Very much like the Google Play Music app works when opening an mp3 file from a file browser). I know I could just get the button to open an intent to use Google Play Music, but I would like my app to have it's own colour scheme of a very similar looking version of the same popup.
The current Java code that I have for one of the songs is as follows:
package com.lmarshall1995.scoutsongs;
import com.lmarshall1995.scoutsongs.R;
import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class Song_AliceTheCamel_Activity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.song_alicethecamel);
setupNavigationButton();
Toast toast = Toast.makeText(this, "To be sung in the tune of \n . . .", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
final Button back = (Button) findViewById(R.id.back_button);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
final Button previous = (Button) findViewById(R.id.previous_button);
previous.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent previousIntent = new Intent(Song_AliceTheCamel_Activity.this, Song_ZipADeeDooDah_Activity.class);
Song_AliceTheCamel_Activity.this.startActivity(previousIntent);
finish();
}
});
final Button next = (Button) findViewById(R.id.next_button);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent nextIntent = new Intent(Song_AliceTheCamel_Activity.this, Song_Bingo_Activity.class);
Song_AliceTheCamel_Activity.this.startActivity(nextIntent);
finish();
}
});
final ImageButton play_tune = (ImageButton) findViewById(R.id.play_tune);
play_tune.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ImageButton play_tune = (ImageButton) findViewById(R.id.play_tune);
play_tune.setOnClickListener(new View.OnClickListener() {
MediaPlayer mp = MediaPlayer.create(Song_AliceTheCamel_Activity.this, R.raw.tune_alicethecamel);
public void onClick(View arg0) {
if (mp.isPlaying()) {
mp.stop();
mp.prepareAsync();
mp.seekTo(0);
} else {
mp.start();
}
}
});
}
});
}
private void setupNavigationButton() {}
}
And the current xml code that I have for one of the songs is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/song_alicethecamel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
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=".ScoutSongs" >
<TextView
android:id="#+id/Song_AliceTheCamel_Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="#string/Song_AliceTheCamel_Title"
android:textSize="20sp"
android:textColor="#FFFFFF" />
<ImageButton
android:id="#+id/play_tune"
android:src="#drawable/play_tune"
android:contentDescription="#string/play_tune"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/Song_AliceTheCamel_Title"
android:layout_alignTop="#+id/Song_AliceTheCamel_Title" />
<ScrollView
android:id="#+id/Song_AliceTheCamel_Lyrics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/back_button"
android:layout_alignLeft="#+id/Song_AliceTheCamel_Title"
android:layout_alignRight="#+id/play_tune"
android:layout_below="#+id/play_tune">
<TextView
android:id="#+id/Song_A_Lyrics1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/Song_AliceTheCamel_Lyrics"
android:textColor="#FFFFFF" />
</ScrollView>
<Button
android:id="#+id/back_button"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/Song_AliceTheCamel_Lyrics"
android:text="#string/back"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/previous_button"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/back_button"
android:layout_alignBottom="#+id/back_button"
android:layout_alignLeft="#+id/Song_AliceTheCamel_Lyrics"
android:text="#string/previous"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/next_button"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/previous_button"
android:layout_alignBottom="#+id/previous_button"
android:layout_toRightOf="#+id/previous_button"
android:text="#string/next"
android:textColor="#FFFFFF" />
</RelativeLayout>
but I would rather have it looking more like this:
Any help would be much appreciated as I know the source code for this is obviously going to be protected, At the moment, all I know is I need to make an xml file for the layout, and I think that would be a good start to ask for guidance.
Once I have this information, I would like to change the background to black rather than white, the seek bar to purple rather than orange, and change what Text is displayed to the song Title, rather than the file name.
Implement the audio player as a fragment which communicates with a background service through a messaging tool like the LocalBroadcastReceiver or Otto. Then in the application when the user wants to play a song they can select it and you can create a DialogFragment with the new Fragment you created. Thats how I've done this before.

Cancel button in dialog not dismissing dialog

I have a dialog that I launch with:
// custom dialog
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.add_taste_dialog);
dialog.setTitle("Add Taste");
Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner) dialog.findViewById(R.id.spinner2);
Button dialogButton = (Button) dialog.findViewById(R.id.cancelButton);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
The problem is that when I click the button it does not dismiss the dialog.
My dialog xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tastePickTitle"
android:text="Select a Taste: "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:textStyle = "bold"
android:padding="5dip"
>
</TextView>
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/taste_array"
/>
<View
android:layout_width="fill_parent"
android:layout_height="30dp">
</View>
<TextView
android:id="#+id/ammountPickTitle"
android:text="How much taste: "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:textStyle = "bold"
android:padding="5dip"
>
</TextView>
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/ammount_array"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_weight="1"
/>
<Button
android:id="#+id/addTasteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
android:layout_weight="1"
android:onClick="addTasteNow" />
</LinearLayout>
</LinearLayout>
Here is the full taste tag java code to give the snipet above some more context:
public class TasteTags extends Activity {
BeerData e;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tastetag_page);
//get beer data
Intent intent = getIntent();
Bundle b = intent.getExtras();
e = b.getParcelable("myBeerObject");
TextView beerTitle = (TextView) findViewById(R.id.beerTitleTaste);
beerTitle.setText(e.beerName + " Taste Profile");
String url = "myURL";
url = url + "b=" +e.beerId;
//async task to get beer taste tag percents
new GetTasteJSON(this).execute(url);
}
public void addTaste(View v){
// custom dialog
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.add_taste_dialog);
dialog.setTitle("Add Taste");
Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner) dialog.findViewById(R.id.spinner2);
Button dialogButton = (Button) dialog.findViewById(R.id.cancelButton);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("dialog", "cancel pressed");
dialog.dismiss();
}
});
dialog.show();
}
}
make final Dialog dialog = null; a global variable (activity level), remove the final and initialize at it where you have it right now, that is fine.
Looking at your code nothing jumps out, if you post your full code or a simple example to replicate i'm sure someone could fully decipher the problem. I have included some sample snippets that show a dialog that work, take a look at those to see if they shed any insight as to why yours does not work.
One thing to check before looking at the working sample, make sure you don't have a button in your dialog view with id 'cancelButton' defined twice(common from copy/paste errors). This will cause the behavior you are seeing. If you take the working example below and use the following view it will reproduce your behavior:
Broken Dialog View
<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"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:text="close" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:text="close" />
See below for working example.
Dialog View:
<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"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:text="close" />
Application class
package com.example.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Add Taste");
Button dialogButton = (Button) dialog.findViewById(R.id.button1);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}

Android App - Radio Buttons, TextView, and Layout Options

I'm creating my first android app. It seems fairly simple. But I'm a total noob with Java and Android (I'm more familiar with C, C++ and the like). I'm sorry if this is the dumbest question ever. Anyway, I followed the steps on the android dev website.
The app is supposed to have the person enter their Name and click on 1st, 2nd, or 3rd shift radio buttons and when they click on Downtime Button, they'll be brought to another page (activity) that displays their name and the shift they picked and then displays another textbox and a time input.
So far, I got the MainActivity.java done like this:
package com.cyapps.downtime;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.cyapps.downtime.MESSAGE";
public void clickedButton1(View view) {
Intent intent = new Intent(this, WinderDTActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
public void clickedButton2(View view) {
Intent intent = new Intent(this, ClamperDTActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
public void clickedButton3(View view) {
Intent intent = new Intent(this, OtherDTActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and the activity_main.xml like this:
<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:orientation="horizontal" >
<EditText
android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:ems="10"
android:hint="#string/edit_message" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edit_message"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="#string/radio_button1" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioButton1"
android:layout_centerHorizontal="true"
android:text="#string/radio_button2" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioButton2"
android:layout_centerHorizontal="true"
android:text="#string/radio_button3" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button2"
android:layout_centerHorizontal="true"
android:text="#string/button_send1"
android:onClick="clickedButton1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button3"
android:layout_centerHorizontal="true"
android:text="#string/button_send2"
android:onClick="clickedButton2" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:text="#string/button_send3"
android:onClick="clickedButton3" />
</RelativeLayout>
I now have another activity that shows up when you finish entering in your name and clicking on a shift. This page is supposed to show your name and the shift number and have a textbox to write some other stuff in it and a time input and a submit button. I know how to do buttons and I see the time input on the interface of Eclipse. But I don't understand how to make the radio buttons be able to be "submitted" and shown on the page and how to edit the activity to show certain stuff. I'm confused.
This is how the WinderDTActivity.java looks like:
package com.cyapps.downtime;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class WinderDTActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
}
And this is what the activity_winder_dt.xml looks like:
<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" >
</RelativeLayout>
Thank you so much in advance if you help me. You have no idea how grateful I'll be. I've been trying really hard to understand this, but I'm thoroughly confused on how to get xml and java working together. Please help!
You're already sending the contents of the text box to the second activity just fine, right? Then you only need to do two more things to send the radio button state through as well:
Implement onClick handlers for the radio buttons. You've already done that for the submit buttons, so I assume you've figured out onClick stuff. In the radio button onClick, set a variable in MainActivity.
Package the variable the radio flags set into the intent's extra data, like so:
intent.putExtra("radioButtonState", radioButtonState);
You can read the result back in your second activity using the appropriate intent.getxxxxExtra() function (getIntExtra if you saved an int, for example).
you have to not written Button b1=(Button)findViewById(R.id.Button1) in onCreate methid
this is the reason your are not getting button click event
similarly write code for button2 and button3

How to focus to the top of newly generated text in textView?

I have a simple jokes application. When you press the button you get new joke. If the previous one was bigger than the screen you can scroll it down. If you go down to the bottom and you go to the next joke, you are transfered to the bottom of the newly generated joke, but i want it to go to the top, and automatically display the start of the joke. How can i do this ?
I assume it would be done via the java code.
Thank you for your time.
Use the scrollTo(int x, int y) method, i like to have ScrollView around my TextView but i think the same thing will work for a TextView only. hope you understand!
Rolf
Example
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" >
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="130dp" >
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="long\n\n\n\n\n\n\n\n long\n\n\n\n\n\n\n very text here!" />
</ScrollView>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="joke" />
</LinearLayout>
java:
package org.sample.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
public class AutoscrollActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private Button new_joke;
private TextView joke;
private ScrollView scroll;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new_joke = (Button) this.findViewById(R.id.button);
new_joke.setOnClickListener(this);
joke = (TextView) this.findViewById(R.id.text);
scroll = (ScrollView) this.findViewById(R.id.scroll);
}
#Override
public void onClick(View v) {
joke.setText("Long\n\n\n\n\n\n\n\n joke \n\n\n\n\n\n\n\nlong joke joke");
scroll.scrollTo(0, 0);
}
}

Show/Hide webview issue

I'm working in an application that has in the same view a set of buttons and a web view(GONE), when the app starts it shows only the buttons from where at a click it shows the web view and loads a url (the layout where the buttons are is set to GONE) that contains a flash media player and a single button that when is click it makes the web view invisible again and shows the first layout that contains the buttons to be able to choose a different website, the problem is that when the web view goes invisible the flash media players stays stuck on the screen and blocks the buttons, how can I fix this? It would be ok if the media player stays behind the buttons but I cannot find an answer, any help will be highly appreciated, Thank you.
Update with Code:
<?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:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_width="match_parent" android:orientation="vertical">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Web 1" android:id="#+id/buttonWeb1"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/buttonWeb2" android:text="Web 2"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Web 3" android:id="#+id/buttonWeb3"></Button>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="#+id/linearLayout2" android:layout_width="match_parent" android:orientation="vertical">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/buttonBack" android:text="Back to Buttons"></Button>
<WebView android:layout_height="match_parent" android:layout_width="match_parent" android:id="#+id/webView"></WebView>
</LinearLayout>
And the main Activity
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.LinearLayout;
public class FlashejemploActivity extends Activity {
WebView wv;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
final LinearLayout buttons = (LinearLayout) findViewById(R.id.linearLayout1);
final LinearLayout webV = (LinearLayout) findViewById(R.id.linearLayout2);
final Button web1 = (Button) findViewById(R.id.buttonWeb1);
final Button web2 = (Button) findViewById(R.id.buttonWeb2);
final Button web3 = (Button) findViewById(R.id.buttonWeb3);
final Button back = (Button) findViewById(R.id.buttonBack);
wv = (WebView) findViewById(R.id.webView );
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
wv.setWebViewClient(new WebViewClient());
wv.setInitialScale(1);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setUseWideViewPort(true);
final Activity PActivity = this;
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
PActivity.setTitle("Cargando....");
PActivity.setProgress(progress * 100);
if(progress == 100)
PActivity.setTitle(R.string.app_name);
}
});
webV.setVisibility(View.GONE);
web1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
buttons.setVisibility(View.GONE);
webV.setVisibility(View.VISIBLE);
wv.loadUrl("http://los40.com.mx/Player.htm");
}});
web2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
buttons.setVisibility(View.GONE);
webV.setVisibility(View.VISIBLE);
wv.loadUrl("http://www.beat1009.com.mx/n2/paginas/radio.php");
}});
web3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
buttons.setVisibility(View.GONE);
webV.setVisibility(View.VISIBLE);
wv.loadUrl("http://besame.com.mx/Player.htm");
}});
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
buttons.setVisibility(View.VISIBLE);
webV.setVisibility(View.GONE);
}});
}
}
I know its been a while but I have just solved a similar problem by getting the webview to empty
wv.loadUrl("about:blank");

Categories

Resources