0

ill explain it simple. i have button and a layout (about_dialog.xml) when you click on button a dialog shows up with the layout contents and working fine... but when i want to change the (about_dialog.xml) content with codes in (about_dialog.java) it wont change! i mean when you click on the button the layout shows up in a dialog with the same content...

LOOK AT THE CODES , YOU WILL GET IT!

onclick code in my Main activity

FloatingActionButton fab =(FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Dialog dialog = new Dialog(Main.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.about_dialog);
            dialog.show();


        }
    });

about_dialog :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dialogLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/md_white_1000"
android:orientation="vertical"
tools:context="rappage.rapfarsi.media.appteam.todaymusic.todaymusic">

<TextView
    android:id="@+id/textViewAboutDialogTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="24dp"
    android:text="About"
    android:textAppearance="@style/TextAppearance.AppCompat.Title"
    android:textColor="#DDD" />

<TextView
    android:id="@+id/textViewAboutDialogDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="24dp"
    android:layout_marginRight="24dp"
    android:text="@string/kingx"
    android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
    android:textColor="#CCC" />


<TextView

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_column="1"
    android:layout_marginBottom="24dp"
    android:layout_marginLeft="24dp"
    android:layout_row="2"
    android:autoLink="web"
    android:text="MY SITE"
    android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
    android:textColor="?attr/colorAccent"
    android:textColorLink="?attr/colorAccent"
    android:id="@+id/site" />

</LinearLayout>

todaymusic.java (the java file for about_dialog)

package rappage.rapfarsi.media.appteam.todaymusic;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;

import rappage.rapfarsi.media.appteam.R;


public class todaymusic extends ActionBarActivity {

// Declaring Your View and Variables


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_dialog);

    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    TextView tvsite =(TextView) findViewById(R.id.site);
int x=0;

if(x == 0)

{

tvsite.setText("yes its 0");

}


}



}
  • I looked at the "codes" but I don't get it. – Egor Aug 09 '15 at 17:04
  • Thread.currentThread().setPriority(Thread.MAX_PRIORITY); what does this code do? – P-RAD Aug 09 '15 at 17:16
  • it makes the priorty to high means use more memory(ram) to run quicker , we use it for long & heavy processes.... but i put it all over my app bcz its badly heavy! @Dev –  Ali Mohamadi Aug 09 '15 at 18:57

1 Answers1

0

In your main activity, you use

dialog.setContentView(R.layout.about_dialog);

That's the reason why your activity is never called and it always shows the content of your XML. If you want to display your dialog as an activity, don't instantiate your dialog on your listener but use startActivity(intent) to call your activity.

You can find a lot of tutorial on how to make a Dialog Activity on the Internet.

For example : Android: how to create a transparent dialog-themed activity

or How to create Dialog activity in Android?

Community
  • 1
  • 1
Neeko
  • 1,139
  • 1
  • 10
  • 26