Android: Activity Intent open without the xml file



I have got some strange problem. I've opend new Intent activity and started it by button click but when the activity start its open the new page but without the xml file just a black activity page. (This is the Main/Second Activity codes with the Xml codes, when the SecondActivity is open(Startactivity) i got blackactivity page in the Device) MainActivity



public class MainActivity extends Activity {

//all buttons i need for the actions
Button buttonAdd;
Button buttonShow;
Button buttonDelet;
Intent addbtn;
Intent showbtn;
ArrayList<String> events= new ArrayList<String>();//new arraylist for saving events


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

buttonAdd =(Button) findViewById(R.id.add);
buttonShow =(Button) findViewById(R.id.show);
buttonDelet =(Button) findViewById(R.id.delet);
addbtn = new Intent(this,SecondActivity.class);
showbtn = new Intent(this,ThirdActivity.class);
//buttonAdd.setOnClickListener(this);
}

private void buttonAddClick(){
// startActivity(new Intent(this,SecondActivity.class));
startActivity(addbtn);
}
private void buttonShowClick(){
//startActivity(new Intent(this,ThirdActivity.class));
startActivity(showbtn);
}

public void onClick(View v) {

switch (v.getId()){
case R.id.add:
buttonAddClick();
break;
case R.id.show:
buttonShowClick();
break;
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


Xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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" >

<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="@string/show_event" />

<Button
android:id="@+id/delet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/delet_event" />

<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="@string/add_event" />

</LinearLayout>


Second Activity



public class SecondActivity extends Activity{

MainActivity m;
Button buttonSave;
Button buttonBack;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

buttonSave =(Button) findViewById(R.id.savebtn);
buttonBack =(Button) findViewById(R.id.backbtn);
//buttonSave.setOnClickListener(v);
}

public void onClick2(View v) {
if (v.getId()== R.id.savebtn)
{
EditText TextD = (EditText)findViewById(R.id.datet);
String Date = TextD.getText().toString();
EditText TextT = (EditText)findViewById(R.id.typet);
String Type = TextT.getText().toString();
String FinalDate = Type + Date;
m.events.add(FinalDate);
}
else
if (v.getId()== R.id.backbtn)
{
finish();
}
}

}


Xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".SecondActivity" >

<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date" />

<EditText
android:id="@+id/datet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="70px" />

<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/type" />

<EditText
android:id="@+id/typet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="70px" />

<Button
android:id="@+id/savebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="OnClick2"
android:text="@string/save" />

<Button
android:id="@+id/backbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick2"
android:text="@string/back" />

</LinearLayout>


How i fix it? So i will get the SecondActivity Xml insted of a black activity after open addbuttonclick in main


No comments:

Post a Comment