What have I missed out here? I wanted to open edit_information
fragment from edit
activity. It can display the Toast
but not displaying the edit_information
layout.
Edit
listViewEdit.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
// Get the cursor, positioned to the corresponding listview_item_row in the result set
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
// Get the state's capital from this listview_item_row in the database.
String ID =
cursor.getString(cursor.getColumnIndexOrThrow("_id"));
EditInformation fragment2 = new EditInformation();
Bundle bundle = new Bundle();
bundle.putString("ID", ID);
fragment2.setArguments(bundle);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment1, fragment2);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
EditInformation
public class EditInformation extends Fragment {
String ID;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View edit_info = inflater.inflate(R.layout.edit_information, container, false);
Bundle bundle = this.getArguments();
if(getArguments()!=null)
{
ID=bundle.getString("ID");
}
Toast.makeText(getActivity(),"Edit_Information",Toast.LENGTH_LONG).show();
return edit_info;
}
}
edit
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment1">
<RelativeLayout
android:layout_width="209dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/tomato"
android:paddingLeft="10sp"
android:textSize="20sp"
android:paddingTop="10sp"
android:hint="Long Press to delete"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/tomato"
android:paddingTop="40sp"
android:textSize="20sp"
android:paddingLeft="10sp"
android:hint="Hint to edit"/>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listViewEdit"
android:paddingTop="10sp"/>
</LinearLayout>
edit_information
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10sp"
android:orientation="vertical"
android:background="@color/beige">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_corner_up"
android:padding="10dp"
android:text="Name"
android:textColor="@color/tomato"
android:textSize="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Name"
android:layout_marginTop="-15dp"
android:background="@drawable/round_corner_up">
<Spinner
android:layout_width="339dp"
android:layout_height="52dp"
android:id="@+id/SpinnerName" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:id="@+id/Weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_corner_up"
android:padding="10dp"
android:text="Weather"
android:textColor="@color/tomato"
android:textSize="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Weather"
android:layout_marginTop="-15dp"
android:background="@drawable/round_corner_up">
<Spinner
android:layout_width="342dp"
android:layout_height="52dp"
android:id="@+id/SpinnerWeather">
</Spinner>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Date"
android:background="@drawable/round_corner_up"
android:padding="10dp"
android:text="Date"
android:textColor="@color/tomato"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Date"
android:layout_marginTop="-15dp"
android:background="@drawable/round_corner_up">
<EditText
android:layout_width="311dp"
android:layout_height="52dp"
android:layout_margin="10sp"
android:background="@drawable/round_corner_square"
android:id="@+id/date"
android:paddingLeft="20dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Status"
android:background="@drawable/round_corner_up"
android:padding="10dp"
android:text="Status"
android:textColor="@color/tomato"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Status"
android:layout_marginTop="-15dp"
android:background="@drawable/round_corner_up">
<Spinner
android:layout_width="339dp"
android:layout_height="52dp"
android:id="@+id/SpinnerStatus">
</Spinner>
</LinearLayout>
</RelativeLayout>
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20sp"
android:orientation="horizontal">
<Button
android:layout_width="187dp"
android:layout_weight="0.83"
android:text="Add Work Force"
android:textSize="20sp"
android:drawableRight="@mipmap/add_workforce"
android:layout_height="75dp"
android:id="@+id/AddForce"
android:layout_x="12dp"
android:layout_y="11dp" />
<Button
android:layout_width="123dp"
android:layout_weight="0.83"
android:text="Next"
android:textSize="20sp"
android:drawableRight="@mipmap/next"
android:layout_height="71dp"
android:id="@+id/Next"
android:layout_x="211dp"
android:layout_y="14dp" />
</AbsoluteLayout>
</LinearLayout>