Do not see any change on runtime eclipse android - android

I Change an activity background color in eclipse,but I don't any change in run time. why?
this is activity XML code,I use android:background="#ff0000" to change background cokor:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:content=".TestingDetailsActivity"
android:background="#ff0000">
<Button
android:id="#+id/btnExistsTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/ExamList" />
</LinearLayout>
and java code:
package com.tutecentral.restfulapiclient;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TestingDetailsActivity extends Activity {
Button btnExistsTest;
protected void onCreate() {
//super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing);
btnExistsTest=(Button) findViewById(R.id.btnExistsTest);
btnExistsTest.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(TestingDetailsActivity.this,ExamListActivity.class);
startActivity(i);
}
}) ;
}
}

Manually uninstall the APK file from your phone and then re-run the app from your IDE. Sometimes these kind of glitches happen.

Related

my app is not running still in my phone but is not showing any error

It Shows no error on Android Studio but app even not starting on phone.Is there any problem with the code.I feel like there may be any mistakes in syntax but i am not able to find one.Please help me.
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button bDriver,bCustomer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bDriver=(Button)findViewById(R.id.driver);
Button bCustomer=(Button)findViewById(R.id.customer);
bDriver.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new
Intent(MainActivity.this,DriverLoginActivity.class);
startActivity(intent);
finish();
}
});
bCustomer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent ryt=new
Intent(MainActivity.this,CustomerLoginActivity.class);
startActivity(ryt);
finish();
}
});
}
}
And activity_main.xml is this and please explain if there is any problem related to SDK version also upload the detail.
<?xml version="1.0" encoding="utf-8"?>
<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: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="com.trillcore.uber.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/driver"
android:layout_below="#+id/customer"
android:text="I am a Driver"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Customer"
android:layout_above="#+id/driver"
android:id="#+id/customer"/>
</RelativeLayout>

put two pages and access with one button in android

hello I want put one button . when click that button from this page go to another page. I think I use Relative layout but I don't know exactly how to use it. please put complete code from "main.xml" and "activity" because I'm an amateur!!! thanks
Oh silverboy...
MainActivity:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to second page"/>
</RelativeLayout>

App Crashing instantly, unexplained

My code is written to first bring up a button in the LoginActivity and then when pressed load another activity. But as of right now, the app crashes both on my S4 and an emulator on launch. I have tried debugging mode but haven't received any useful information. Here is my LoginActivity code (main activity):
package com.JTInc.tag;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
public class LoginActivity extends FragmentActivity {
public void gotomap (View View){
Intent ii = new Intent(getActivity(), MapActivity.class);
startActivity(ii);
}
private void startActivity(Intent ii) {
// TODO Auto-generated method stub
}
private Context getActivity() {
//TODO Auto-generated method stub
return null;
}
}
Here is the mapviewer.xml code (the main layout)
<?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" >
<Button
android:id="#+id/gotomap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gotomap"
android:onClick="gotomap" />
</LinearLayout>
Any and all help is appreciated, Thanks.

Android Google Map API V2 - Buttons above fragment

I have managed to get a map to show on the screen. I am trying to create buttons above the map and then add actions to this. E.g. the button will change the location of the map. I am basically trying to adapt my code to this: https://www.youtube.com/watch?v=awX5T-EwLPc. However, I am using "extends Fragment Activity" which messes everything up.
My problem: I cannot create a button above the map, it is placed inside the map. I am trying to create a button above the map, and assign code so I can move to a location on the map etc. Here is my code:
MainActivity.java
package com.example.theapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends FragmentActivity implements OnClickListener
{
Button button;
TextView text;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button1);
text=(TextView)findViewById(R.id.textView1);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
text.setText("The button worked!");
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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: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=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/map"
android:layout_alignTop="#+id/map"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignRight="#+id/map"
android:layout_marginRight="39dp"
android:text="TextView" />
</RelativeLayout>
From the code, my app displays a button on the map and a text view. When you click the button, its meant to change the text, but it doesn't do anything. I have researched tutorials and by the looks of it, I will have to create multiple fragments?
Question: How would I be able to create a button on that page, that will then pin point the user on the map?
Thank you in advance.
You are not setting any functionality to the Button... You should use
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text.setText("that's how you do it!");
}
});
You need not to worry about "FragmentActivity" until and unless you use fragment class.
Just use this as normal Activity. it will work well.
package com.example.theapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends FragmentActivity implements OnClickListener
{
Button button;
TextView text;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(this);
text=(TextView)findViewById(R.id.textView1);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
text.setText("The button worked!");
}
}

why am I getting errors when I use different backgrounds in xml

I have 3 activities which I want to use different backgrounds with. but when i do this i get this i get this error however if i only use different backgrounds on 2 activities then the app works
11-20 13:40:25.855: E/AndroidRuntime(849): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.medepad.community_virtual_ward/com.medepad.community_virtual_ward.Temperature}: android.view.InflateException: Binary XML file line #2: Error inflating class
the activities are called main welcome and temperature.
code for main
xml
<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: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=".MainActivity"
android:background="#drawable/main" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="400dp"
android:layout_marginTop="115dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="40dp" />
</RelativeLayout>
java code
package com.medepad.community_virtual_ward;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
int a;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView start = (TextView)findViewById(R.id.textView1);
start.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent welcome= new Intent (this,Welcome.class);
startActivity(welcome);
}
}
code for temperature
<?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"
android:background="#drawable/temperature" >
</LinearLayout>
java code
package com.medepad.community_virtual_ward;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class Temperature extends Activity implements OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.temperature);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
welcome xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/welcome" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="400dp"
android:layout_marginTop="115dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="40dp" />
</RelativeLayout>
java code
package com.medepad.community_virtual_ward;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class Welcome extends Activity implements OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
TextView next= (TextView)findViewById(R.id.textView2);
next.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent temperature= new Intent(this, Temperature.class);
startActivity(temperature);
}
}
why am i getting this error and what can i do to use the amount of backgrounds i want?
The end of your first XML file has an extra >.
Please check the following file
temperature.xml
Make sure, it has following contents
<?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"
android:background="#drawable/temperature" >
</LinearLayout>
and you have either defined a drawable resource with name temperature.xml and main.xml under res/drawable folder or you have added image resources with name temperature and main in your Android project.

Categories

Resources