I am trying to pass an Intent from my mainScreen Activity class to a new android class with a layout that contains a ListView ..
MainActivityScreen Code : (TimePassed is in the format of 'HH:MM:SS')
public void MoveToShiftsPage(View view) {
Intent shiftsIntent=new Intent(this,Shifts.class);
shiftsIntent.putExtra("time",TimePassed);
startActivity(shiftsIntent);
}
"MoveToShiftsPage" in the MainActivity.xml file :
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/payment"
android:id="@+id/shiftbtn"
android:onClick="MoveToShiftsPage"
/>
Shifts.xml File( the layout which contains the ListView and the Intent sent to it)
<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" tools:context=".MainScreen"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:id="@+id/MyListView"
android:clickable="true"
style="@style/Base.Widget.AppCompat.ListView.DropDown">
</ListView>
/>
and the Shift.class which gets the Intent and it's supposed to represent the ListView with the time that passed :
import android.app.Activity;
import android.content.Intent;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.util.List;
/**
* Created by user on 19/09/2015.
*/
public class Shifts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shifts);
Intent MyIntent=getIntent();
String TimePassed=MyIntent.getStringExtra("time");
String [] timepass=TimePassed.split(":");
ListAdapter theAdapter=new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_activated_1,timepass);
ListView thelist=(ListView)findViewById(R.id.MyListView);
thelist.setAdapter(theAdapter);
}
}
Unfortunately whenever I click on the image button which is supposed to be sent to the shift activity class and represents the layout with the ListView the app crashes .. what should I do ?