I have created an activity and now I am trying to add an eventListener to a button:
But when I switch to the AddEntryActivity I get an SuperNotCalledException().
Any help is really appreciated!
public class AddEntryActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_entry);
ImageButton test = (ImageButton) findViewById(R.id.mg_add_entry_button_save);
...
Here is my activity_add_entry.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:background="#drawable/radialback">
<LinearLayout
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:id="#+id/mg_overview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="#+id/mg_menu_bar">
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="numberDecimal">
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="date"/>
<Spinner
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/mg_add_entry_spinner_categories"
android:entries="#array/basic_categories_array"
android:prompt="#string/abc_activity_chooser_view_see_all"></Spinner>
<Button
android:id="#+id/mg_add_entry_button_save"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="#string/mg_save"/>
</LinearLayout>
<LinearLayout
android:id="#+id/mg_menu_bar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/mg_menu_button_add_entry"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/abc_ic_go"/>
</LinearLayout>
</RelativeLayout>
Hard to say without seeing your logcat, but chances are that you're overriding some method in the previous activity class (such as onPause or onStop), and you're missing the call to super.-
#Override
public void onPause() {
super.onPause();
// Your stuff
}
Related
my app contains "Settings" activity which contains 2 imagebuttons "back" and "about", whenever i press any of these buttons i get:
"couldnt save which view has focus because the focused view android.widget.LinearLayout#4055a9e0 has no id"
the xml code for my_settings:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll2"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="8dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/settings" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|end"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/tb1"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="#string/sett1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border2"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_back"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/back_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_about"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/about_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
dont pay attention to the "scrollview" (i dont think the problem is there), just look at the end of the code for the 2 imagebuttons..
and this the java code for Settings:
public class Settings extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.my_settings);
//code...
ImageButton goBack=(ImageButton)findViewById(R.id.st_ibt1);
ImageButton about=(ImageButton)findViewById(R.id.st_ibt2);
goBack.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, MainActivity.class);
startActivity(intent);
//finish();
}
});
about.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, About.class);
startActivity(intent);
//finish();
}
});
}
so, how to fix this? i dont understand what this error means.. any suggestions
I think the problem is :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
You enable focus to this LinearLayout, but you didn't provide any id for it.
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 ;)
I have an activity which loads in a linear layout from XML file.
What I want is that an additional textview and a button should appear when the application is run. BUT it should never appear again when the user clicks on "bGotIt" button [using the sharedpreferences stuff]
But what I want is that the textview and button must appear at the top of the activity and must push down my permanent components !! And when the "bGotIt" button is clicked, both these textview and button should disappear and the permanent components must pull themselves up and fill the screen.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/firstTimeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bla bla bla bla "
/>
<Button
android:id="#+id/bGotIt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Got it !! "
android:visibility="gone"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
Here I have my permanent components
</RelativeLayout>
</FrameLayout>
</LinearLayout>
// try this way, hope this will help you...
Note : i try to put this "Button" and "TextView" in one layout and just try to change layout visibility (Show/Hide) on "bGotIt" "Button" click.
**activity_main**
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/lnrHidable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/done"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/firstTimeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bla bla bla bla "/>
</LinearLayout>
<Button
android:id="#+id/bGotIt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Got it !! "
android:visibility="gone"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
Here I have my permanent components
</RelativeLayout>
</FrameLayout>
</LinearLayout>
**MyActivity**
public class MyActivity extends Activity{
private LinearLayout lnrHidable;
private Button bGotIt;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lnrHidable = (LinearLayout) findViewById(R.id.lnrHidable);
bGotIt = (Button) findViewById(R.id.bGotIt);
// visiable as your sharedpreferences
bGotIt.setVisibility(View.VISIBLE);
bGotIt = (Button) findViewById(R.id.bGotIt);
bGotIt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
lnrHidable.setVisibility(View.GONE);
}
});
}
}
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 ran up against a few problems when i use Slidingdrawer. How to fix it.
Main 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"
android:background="#color/white">
<SlidingDrawer
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/black"
android:handle="#+id/handle"
android:id="#+id/slideD">
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#id/handle"
android:background="#drawable/arrow_up"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/ic_launcher"
>
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/ic_launcher"
>
</Button>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
Activity
public class ATDTActivity extends Activity {
SlidingDrawer slideD;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
slideD = (SlidingDrawer)findViewById(R.id.slideD);
slideD.setOnDrawerOpenListener(new OnDrawerOpenListener(){
#Override
public void onDrawerOpened() {
slideD.getHandle().setBackgroundResource(R.drawable.arrow_down);
}
});
slideD.setOnDrawerCloseListener(new OnDrawerCloseListener(){
#Override
public void onDrawerClosed() {
sideD.getHandle().setBackgroundResource(R.drawable.arrow_up);
}
});
}
}
Thank for help!.
Your post does not have much context to explain the code sections; please explain your scenario more clearly.
Add content to SlidingDrawer:
....
<SlidingDrawer
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:content="#+id/content"
android:handle="#+id/handle"
android:id="#+id/slideD">
........
<LinearLayout
android:id="#id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
.......
Don't even bother with this class.
This class was deprecated in API level 17.