My activity should show a custom dialog with some options and depending upon options should commit a layout change without dismissing the dialog. Is it possible? Any ideas?
try this,
First makecustom.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cat" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Hey there i am cat"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
then in activity_main.xml add following code,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />`</RelativeLayout>`
then in MainActivity.java,
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button B = (Button) findViewById(R.id.button1);
B.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Dialog d = new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("This is custom dialog box");
d.show();
}
});
}
thats it...
Related
I don't know why do we call activity method onDestroy() then onCreate() after that onPause() methods to dismiss the Dialog.
I don't want to call activity onDestroy() when I call Dialog.dismiss().
What is wrong with this?
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_layout);
dialog.setCancelable(false);
mCancel = (Button) dialog.findViewById(R.id.cancel);
mCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v("log_tag", "Signature Canceled");
dialog.dismiss();
}
});
dialog.show();
Here is dialog_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:orientation="vertical"
android:background="#android:color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:text="#string/dialog_title"
android:textColor="#android:color/white"
android:padding="#dimen/layout_padding10"
android:gravity="center"/>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:background="#android:color/white">
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="#string/hint_cancel"
android:textColor="#android:color/white"
android:background="#color/primary_color" />
<Button
android:id="#+id/clear"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="#string/hint_clear"
android:textColor="#android:color/white"
android:background="#color/primary_color" />
<Button
android:id="#+id/getsign"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="#string/hint_save"
android:textColor="#android:color/white"
android:background="#color/primary_color" />
</LinearLayout>
</LinearLayout>
Here is XML code for reference.
There was recreate() method called in my code so that it was creating activity again.
So I have just removed and got solution.
May be it is so easy but do not know i have tried so much but it's not working :(
I have layout like this way
And i have following java code
public class MainActivity extends FragmentActivity{
private ImageView ivMainMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivMainMenu = (ImageView) findViewById(R.id.ivMainMenu);
ivMainMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("showSlider clicked");
}
});
}
i have tried
android:clickable="true"
but still not working
below is my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlMainHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/tvHeaderText"
style="#style/header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<TextView
android:id="#+id/txtScore"
style="#style/black_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="#dimen/extra_small"
android:background="#drawable/keyboard_btn"
android:padding="#dimen/extra_small"
android:text="#string/finish"
android:textColor="#color/dark_text_color"
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="#+id/ivMainMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
android:src="#drawable/menu" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/rlMainHeader"
android:background="#color/main_bg"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/flMain"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<LinearLayout
android:id="#+id/llMainSlider"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible" >
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/slider" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/dark_text_color"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</RelativeLayout>
in my logcat i am getting following message whenever i click on imageview
04-27 11:09:42.996: V/Provider/Settings(1018): from settings cache , name = sound_effects_enabled , value = 0
also i want to let you know that if i load any fragment in flMain, in that fragment all event is working fine but not on main layout :( also in llMainSlider noting was happening :(
Why don't you try declaring the event on the XML?
It is as simple as this
android:id="#+id/ivMainMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:onClick="myNewMethod" <!--add this extra line!--->
android:src="#drawable/menu" />
and simply on your Main activity add the myNewMethod as am extra function like this
public class MainActivity extends FragmentActivity{
private ImageView ivMainMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void myNewMethod(View v) {
System.out.println("showSlider clicked");
}
Good Luck ;)
After spending enough time unsuccessfully, I am posting it here to seek help. I have a ListFragment called from the following FragmentActivity. In the Layout there is a Submit button on top, so that user can scroll the list and press the Submit button when done with filling in the information. However I can't click this submit button. It never gets focus. How can I fix it?
Thanks for your help.
I have this FragmentActivity:
public class SurveyFragmentAnchor extends FragmentActivity {
Button submit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_survey_fragment);
setTitle("Feedback and Survey");
submit = (Button) findViewById(R.id.submit_button);
submit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.v("SURVEY", "Button pressed");
}
});
}
}
And here is the Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="4dp" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e5e5e5">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#ee000000" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:paddingBottom="10dp"
android:text="Rating (1-5) 5= Excellent, 4=Very good, 3=Good,\n2= Satisfactory, 1= Needs Improvement"
android:textColor="#FFF" />
<Button
android:background="#drawable/button_blue2"
android:textColor="#FFF"
android:id="#+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/my_survey_fragment"
android:text="Submit" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false" >
</ListView>
</LinearLayout>
<fragment
android:name="com.survey.MySurvey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="47dp"
android:id="#+id/my_survey_fragment">
</fragment>
Try using these fields on the button:
android:focusable="true"
android:focusableInTouchMode="true"
I need a little help.I'm using a ViewFlipper to change views in TabActivity but not really sure how to do it.Here is my code :
MainActivity.class
public class Collections extends Activity implements OnClickListener {
ViewFlipper vFlip;
Button genre, recommended, soon;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.collections_layout);
vFlip = (ViewFlipper) findViewById(R.id.tags_flipper);
genre = (Button) findViewById(R.id.genre_btn);
genre.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
recommended = (Button) findViewById(R.id.recom_btn);
recommended.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
soon = (Button) findViewById(R.id.soon_btn);
soon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
}
}
I have three different xml, which I want to load with clicking the buttons.Here is the collection_layout.xml
Collection_layout.xml
<?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"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/actionbar"
android:layout_width="fill_parent"
android:layout_height="65px"
android:background="#drawable/pink_bar"
android:tileMode="repeat"
android:orientation="vertical">
<ImageView
android:src="#drawable/stampii_logo"
android:id="#+id/stampii_logo_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20px"/>
</LinearLayout>
<LinearLayout
android:id="#+id/first_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="#d229ce">
<Button
android:id="#+id/genre_btn"
android:text="By Genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/recom_btn"
android:text="Recommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/soon_btn"
android:text="Expect Soon!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/flip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<ViewFlipper
android:id="#+id/tags_flipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include android:id="#+id/genre" layout="#layout/by_genre" />
<include android:id="#+id/recom" layout="#layout/recommended" />
<include android:id="#+id/soon" layout="#layout/expect_soon" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
So how can i do that?Thanks a lot!
Use ViewFlipper.setDisplayedChild
I am attempting to change the background of a tab of my application by selecting a Radio Button from a RadioGroup, however I am not sure how to go about this.
So far I have
Favs.java:
import android.app.Activity;
import android.os.Bundle;
public class Favs extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favs);
}
}
which points to this .xml file -> favs.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is your favorite color?"
android:padding="3dip"/>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:onClick="onClick" />
<RadioButton android:id="#+id/radio_yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yellow" />
</RadioGroup>
</LinearLayout>
I understand that the android:onClick="onClick" needs to be there however I have no idea what to do after this.
hi use below code for changing the background according to radio button selection
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
android:id="#+id/LinearLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is your favorite color?"
android:padding="3dip"/>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Group1"
android:orientation="vertical">
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
/>
<RadioButton android:id="#+id/radio_yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yellow" />
</RadioGroup>
</LinearLayout>
Activity
public class Change extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final LinearLayout ll=(LinearLayout) findViewById(R.id.LinearLayout);
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_yellow = (RadioButton) findViewById(R.id.radio_yellow);
radio_red.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ll.setBackgroundColor(Color.RED);
}
});
radio_yellow.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ll.setBackgroundColor(Color.YELLOW);
}
});
}
}