How to call a fragment from another activity which is not parent? - java

I have an activity which is not parent in that I want to call a fragment in that activity on click of an image view. So I have added onclickListner on my image view. I am getting toast on click of image view but the fragment is not getting called. What can be the issue?? Can anyone help please..
GoSend activity layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/LinearLayoutGoSend">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/LinearContainer">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/DriversNear"
android:id="#+id/textView10"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp" />
<fragment android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/map"
tools:context=".GoSend"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/From"
android:id="#+id/textView11"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView11"
android:background="#drawable/line2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from"
android:text="#string/Loc"
android:visibility="visible"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:cursorVisible="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from_details"
android:layout_marginEnd="10dp"
android:hint="Location details"
android:cursorVisible="true"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView12"
android:layout_marginStart="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayoutAdditionalContactFrom">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView13"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsFrom"
android:layout_marginEnd="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:text="#string/additionalContact"
android:layout_gravity="center_vertical"
android:layout_marginTop="05dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView15"
android:layout_marginStart="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/LinearLayoutAdditionalContactTo">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView18"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsTo"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="05dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:id="#+id/LinearLayoutTo">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTex"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTe"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="OR"
android:id="#+id/textView"
android:layout_gravity="center" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView_next"
android:layout_gravity="center_horizontal"
android:layout_weight="0.42"
android:background="#drawable/ic_chevron_right_black_48dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
GoSend activity
public class GoSend extends AppCompatActivity {
private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;
private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gosendlayout);
setUI();
if (Build.VERSION.SDK_INT >= 21) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("COURIER");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
edtxt_from=(EditText)findViewById(R.id.editText_from);
edtxt_to=(EditText)findViewById(R.id.editText_to);
locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
next = (ImageView)findViewById(R.id.imageView_next);
try {
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
edtxt_from.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
edtxt_to.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
additionalContactFrom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutFrom.getVisibility() == View.GONE){
linearLayoutFrom.setVisibility(View.VISIBLE);
}else{
linearLayoutFrom.setVisibility(View.GONE);
}
}
});
additionalContactTo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutTo.getVisibility() == View.GONE){
linearLayoutTo.setVisibility(View.VISIBLE);
}else{
linearLayoutTo.setVisibility(View.GONE);
}
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearContainer, fragment).commit();
Toast toast = Toast.makeText(getApplicationContext(),"Done",Toast.LENGTH_LONG);
toast.show();
}
});
}
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
}
}
DetailsFragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView22"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/payment"
android:id="#+id/textView24"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView23"
android:background="#drawable/line2"
android:layout_marginTop="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:weightSum="1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView24"
android:background="#drawable/coins49"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/price"
android:id="#+id/textView25"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView26"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView26"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView25"
android:layout_marginStart="10dp"
android:background="#drawable/currency13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/total"
android:id="#+id/textView27"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView28"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView27"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView28"
android:layout_marginStart="10dp"
android:background="#drawable/credit101" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/paywith"
android:id="#+id/textView29"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView30"
android:layout_gravity="center_vertical"
android:layout_marginStart="180dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView29"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
DetailsFragment
public class DetailsFragment extends Fragment {
private Toolbar toolbar;
public DetailsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
return view;
}
}
Please help..

There is nothing in your activity layout with android:id="#+id/LinearContainer, and so FragmentManager does not have anywhere to place your DetailsFragment.

Related

Best way to make CardView hide

this CardView
<android.support.v7.widget.CardView
android:id="#+id/cardv"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_margin="8dp"
app:cardElevation="4dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_margin="2dp"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Data:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_date"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Order Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Nº de pedido:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_id"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="#111111"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Nome:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/userName"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Contacto:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_phone"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="123456789"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Morada:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_address"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Metodo de pagamento:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/paymentMethod"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Payment Method"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Estado de pagamento:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/paymentState"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Payment State"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Estado do pedido:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_status"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Status"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Total:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/totalAmount"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Total Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="4"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<info.hoang8f.widget.FButton
android:layout_margin="5dp"
android:id="#+id/btnEdit"
android:text="Estado"
android:textColor="#android:color/white"
android:shadowColor="#android:color/black"
android:layout_weight="1"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_red_light"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<info.hoang8f.widget.FButton
android:id="#+id/btnHide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:onClick="Hide"
android:shadowColor="#android:color/black"
android:text="Finalizr"
android:textColor="#android:color/white"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_blue_light" />
<info.hoang8f.widget.FButton
android:id="#+id/btnDetail"
android:layout_margin="5dp"
android:text="Detalhes"
android:layout_weight="1"
android:textColor="#android:color/white"
android:shadowColor="#android:color/black"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_orange_light"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<info.hoang8f.widget.FButton
android:id="#+id/btnDirection"
android:layout_margin="5dp"
android:text="Direções"
android:layout_weight="1"
android:textColor="#android:color/white"
android:shadowColor="#android:color/black"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_green_dark"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
appears in this list:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="#drawable/bgencomendeas"
tools:context=".OrderStatus">
<Button
android:id="#+id/voltar2"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:background="#color/fbutton_color_transparent"
android:text="Voltar"
android:textSize="12sp"
android:textStyle="bold"
tools:ignore="MissingConstraints" />
<pl.droidsonroids.gif.GifImageView
android:id="#+id/imgAndroidInstalike2"
android:layout_width="85dp"
android:layout_height="98dp"
android:layout_alignParentBottom="true"
android:background="#drawable/instalike2"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="297dp"
tools:layout_editor_absoluteY="595dp" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="46dp"
android:id="#+id/listOrders"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
I declared in ViewHolder :
public class OrderViewHolder extends RecyclerView.ViewHolder{
public TextView txtOrderId,txtOrderStatus,txtOrderPhone,txtOrderAddress,txtOrderDate,txtPaymentState,txtPaymentMethod,txtName,txtTotal;
public Button btnEdit,btnHide,btnRemove,btnDetail,btnDirection;
public CardView cardlayoutadapter;
public OrderViewHolder(#NonNull View itemView) {
super(itemView);
txtOrderAddress=(TextView)itemView.findViewById(R.id.order_address);
txtOrderId=(TextView)itemView.findViewById(R.id.order_id);
txtOrderStatus=(TextView)itemView.findViewById(R.id.order_status);
txtOrderPhone=(TextView)itemView.findViewById(R.id.order_phone);
txtOrderDate=(TextView)itemView.findViewById(R.id.order_date);
txtPaymentState=(TextView)itemView.findViewById(R.id.paymentState);
txtPaymentMethod=(TextView)itemView.findViewById(R.id.paymentMethod);
txtName=(TextView)itemView.findViewById(R.id.userName);
txtTotal=(TextView)itemView.findViewById(R.id.totalAmount);
btnEdit=(Button)itemView.findViewById(R.id.btnEdit);
btnRemove=(Button)itemView.findViewById(R.id.btnRemove);
btnHide=(Button)itemView.findViewById(R.id.btnHide);
btnDetail=(Button)itemView.findViewById(R.id.btnDetail);
btnDirection=(Button)itemView.findViewById(R.id.btnDirection);
cardlayoutadapter = (CardView)itemView.findViewById(R.id.cardv);
}
}
when I click the btnHide button it goes to "private void hideOrder" to make sure I want to make it disappear after completing the order, and this is where I wanted to somehow make the cardview disappear with that data, so it's not there to occupy , I have another "layout that makes eliminate", either in GONE or invisibility or put the parameter layout_height == 0
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Vahika.ttf")
.setFontAttrId(R.attr.fontPath)
.build());
setContentView(R.layout.activity_order_status);
#Override
protected void onBindViewHolder(#NonNull OrderViewHolder holder, final int position, #NonNull final Request model) {
holder.txtOrderId.setText(adapter.getRef(position).getKey());
holder.txtOrderStatus.setText(Common.convertCodeToStatus(model.getStatus()));
holder.txtOrderAddress.setText(model.getAddress());
holder.txtOrderPhone.setText(model.getPhone());
holder.txtOrderDate.setText(Common.getDate(Long.parseLong(adapter.getRef(position).getKey())));
holder.txtPaymentMethod.setText(model.getPaymentMethod());
holder.txtPaymentState.setText(model.getPaymentState());
holder.txtName.setText(model.getName());
holder.txtTotal.setText(model.getTotal());
holder.btnHide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
hideOrder(adapter.getRef(position).getKey());
}
});
private void hideOrder(final String key) {
AlertDialog.Builder alertDialog=new AlertDialog.Builder(OrderStatus.this);
alertDialog.setTitle("Olá, "+Common.currentUser.getName());
alertDialog.setMessage("O pedido foi entregue?");
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//linearcardv
//reuests.child(key).removeValue();
//binding.CardView.setVisibility(View.GONE);
//reuests.child(key).setValue(View.INVISIBLE);
cardlayoutadapter.setVisibility(View.GONE);
adapter.notifyDataSetChanged();
Toast.makeText(OrderStatus.this, "Pedido finalizado com sucesso!", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setNegativeButton("Não", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Toast.makeText(OrderStatus.this, "Cancelado", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setIcon(R.mipmap.picture);
alertDialog.show();
}
private void hideOrder(final Integer position) {//Pass selected item position
AlertDialog.Builder alertDialog=new AlertDialog.Builder(OrderStatus.this);
alertDialog.setTitle("Olá, "+Common.currentUser.getName());
alertDialog.setMessage("O pedido foi entregue?");
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//**remove item from list at specific position**
adapter.notifyDataSetChanged();
Toast.makeText(OrderStatus.this, "Pedido finalizado com sucesso!", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setNegativeButton("Não", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Toast.makeText(OrderStatus.this, "Cancelado", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setIcon(R.mipmap.picture);
alertDialog.show();
}

Button onClick() causing force stop

Hello StackOverFlowGeeks!
Currently, I'm learning how to write a basic Android app, that has few buttons.
I have four activities(Java Classes) and four xmls.
I have the RegisterScreen.java that has two buttons(Register and Back button). Currently, I am trying to get back from this RegisterScreen.java to SignInScreen.java. The problem is that when I click on the back button it causes a failure and the app is forced to shut down...
So I've uploaded this way:
1) RegisterScreen.java
2) SignInScreen.java
3) RegisterScreen XML file
4) SignInScreen XML file
Thanks in advance.
RegisterScreen:
public class RegisterScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_screen);
}
public void onClickRegisterButton(View view){
}
public void onClickBackButton(View view) {
Button backBtn = (Button) findViewById(R.id.backBtn);
backBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(RegisterScreen.this, SignInScreen.class);
RegisterScreen.this.startActivity(intent);
}
});
}
}
SignInScreen:
public class SignInScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_screen);
}
#SuppressLint("SetTextI18n")
public void onClickSignInButton(View view){
TextView username = (TextView)findViewById(R.id.username_text);
TextView password = (TextView)findViewById(R.id.password_text);
Button signIn = (Button)findViewById(R.id.sign_in_button);
if (username.getText().toString().equals("Ivan Simeonov") && password.getText().toString().equals("Ivan9603116245")){
signIn.setText("Welcome " + username.getText().toString());
signIn.setBackgroundColor(Color.YELLOW);
setContentView(R.layout.activity_logged_screen);
}else{
signIn.setText("The input data is incorrect! Try again!");
signIn.setBackgroundColor(Color.GREEN);
}
}
public void onClickRegisterButton(View view){
Button register = (Button)findViewById(R.id.register_button);
setContentView(R.layout.activity_register_screen);
}
public void onClickResetPasswordButton(View view){
Button resetPassword = (Button)findViewById(R.id.reset_password_button);
setContentView(R.layout.activity_reset_password_screen);
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.megat0n.startproject.RegisterScreen">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView_Register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/register_your_account_by_filling_up_the_following_data"
android:textAlignment="center"
android:textColor="#android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/enter_username"
android:inputType="textPersonName" />
<EditText
android:id="#+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/enter_firstname"
android:inputType="textPersonName" />
<EditText
android:id="#+id/last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/enter_lastname"
android:inputType="textPersonName" />
<EditText
android:id="#+id/birth_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/enter_birthdate"
android:inputType="date" />
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/enter_email"
android:inputType="textPersonName" />
<EditText
android:id="#+id/email_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/confirm_email"
android:inputType="textPersonName" />
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/enter_password"
android:inputType="textPassword" />
<EditText
android:id="#+id/password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/confirm_password"
android:inputType="textPassword" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/reg_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/register"
android:onClick="onClickRegisterButton"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="#+id/backBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/back"
android:onClick="onClickBackButton"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.megat0n.startproject.SignInScreen">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="56dp"
android:text="#string/welcome_to_the_home_screen"
android:textAlignment="center"
android:textColor="#android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:id="#+id/username_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/username"
android:inputType="textPersonName"
android:textAlignment="center"
android:textStyle="bold" />
<EditText
android:id="#+id/password_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword"
android:textAlignment="center"
android:textStyle="bold" />
<Button
android:id="#+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClickSignInButton"
android:text="#string/sign_in"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="#+id/register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClickRegisterButton"
android:text="#string/register"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="#+id/reset_password_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClickResetPasswordButton"
android:text="#string/reset_password"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Use this onClickBackButton() instead of yours. If you use onClick attribute in your layout, you don't need creating button and click listener.
public void onClickBackButton(View view) {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
Try in RegisterScreen use onBackPressed() method:
backBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onBackPressed();
}
});

setOnClickListener is not getting called on image view

I want to call one fragment onclick of next image view. So I have put OnClickListener on image view but it is not getting called at all..
What can be the issue??
GoSend xml Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/LinearLayoutGoSend">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/DriversNear"
android:id="#+id/textView10"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" />
<fragment android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/map"
tools:context=".GoSend"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/From"
android:id="#+id/textView11"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView11"
android:background="#drawable/line2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from"
android:text="#string/Loc"
android:visibility="visible"
android:drawableRight="#drawable/ic_chevron_right_black_24dp"
android:layout_marginRight="10dp"
android:cursorVisible="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from_details"
android:layout_marginRight="10dp"
android:hint="Location details"
android:cursorVisible="true"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView12"
android:layout_marginLeft="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayoutAdditionalContactFrom">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView13"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsFrom"
android:layout_marginRight="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableRight="#drawable/ic_expand_more_black_24dp"
android:text="#string/additionalContact"
android:layout_gravity="center_vertical"
android:layout_marginTop="05dp"
android:layout_marginLeft="05dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView13"
android:layout_marginLeft="48dp"
android:hint="Input if you're not sender" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView15"
android:layout_marginLeft="48dp"
android:hint="House no./Floor/Landmark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView16"
android:layout_marginLeft="48dp"
android:hint="input if you're not receiver" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1.00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView17"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView16"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_check_circle_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/pickup"
android:id="#+id/textView18"
android:layout_marginLeft="10dp"
android:layout_marginTop="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView20"
android:layout_marginLeft="20dp"
android:background="#drawable/box5"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_pac"
android:layout_marginRight="10dp"
android:hint="Items to deliver"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView_next"
android:layout_gravity="center_horizontal"
android:layout_weight="0.42"
android:clickable="true"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Calling this in GoSend Activity
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();
}
});
GoSend activity
public class GoSend extends AppCompatActivity {
private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;
private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gosendlayout);
setUI();
if (Build.VERSION.SDK_INT >= 21) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("COURIER");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
edtxt_from=(EditText)findViewById(R.id.editText_from);
edtxt_to=(EditText)findViewById(R.id.editText_to);
locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
next = (ImageView)findViewById(R.id.imageView_next);
next.setClickable(true);
try {
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
edtxt_from.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
edtxt_to.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
additionalContactFrom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutFrom.getVisibility() == View.GONE){
linearLayoutFrom.setVisibility(View.VISIBLE);
}else{
linearLayoutFrom.setVisibility(View.GONE);
}
}
});
additionalContactTo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutTo.getVisibility() == View.GONE){
linearLayoutTo.setVisibility(View.VISIBLE);
}else{
linearLayoutTo.setVisibility(View.GONE);
}
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();
}
});
}
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
Bundle bundle = getIntent().getExtras();
if(bundle != null)
stringAddress = bundle.getString("address");
}
}
DetailsFragment
public class DetailsFragment extends Fragment {
private Toolbar toolbar;
public DetailsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
return view;
}
}
Fragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView22"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/payment"
android:id="#+id/textView24"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView23"
android:background="#drawable/line2"
android:layout_marginTop="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:weightSum="1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView24"
android:background="#drawable/coins49"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/price"
android:id="#+id/textView25"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView26"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView26"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView25"
android:layout_marginStart="10dp"
android:background="#drawable/currency13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/total"
android:id="#+id/textView27"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView28"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView27"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView28"
android:layout_marginStart="10dp"
android:background="#drawable/credit101" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/paywith"
android:id="#+id/textView29"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView30"
android:layout_gravity="center_vertical"
android:layout_marginStart="180dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView29"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
Please Help...
why are you using these below lines of code, please remove them and check the effect:-
android:clickable="true"
next.setClickable(true);
It's not realize to work but it works in maximum cases.
If you set the view to be clickable, then it will consume the click and not propagate it to the container.

switch to another activity with swipe is not working

My requirement :-
I have two activities..When I swipe it will go to another activity..
So,I have :--
MainActivity.java
public class MainActivity extends Activity {
private GestureDetectorCompat gestureDetectorCompat;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_getservice);
gestureDetectorCompat = new GestureDetectorCompat(this, new MyGestureListener());
}
#Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetectorCompat.onTouchEvent(event);
return super.onTouchEvent(event);
}
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
//handle 'swipe left' action only
#Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
if(event2.getX() < event1.getX()){
//switch another activity
Intent intent = new Intent(
MainActivity.this, Join_form.class);
startActivity(intent);
finish();
}
return true;
}
}
}
and Join_form.java
public class Join_form extends Activity {
private GestureDetectorCompat gestureDetectorCompat;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gestureDetectorCompat = new GestureDetectorCompat(this, new MyGestureListener());
}
#Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetectorCompat.onTouchEvent(event);
return super.onTouchEvent(event);
}
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
//handle 'swipe left' action only
#Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
if(event2.getX() > event1.getX()){
//switch another activity
Intent intent = new Intent(
Join_form.this, MainActivity.class);
startActivity(intent);
finish();
}
return true;
}
}
}
activity_getservice.xml is:--
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#0b2607"
>
<TextView android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Form"
android:layout_marginTop="30dp"
android:padding="10dp"
android:textSize="20dp"
android:layout_gravity="center"/>
<View android:id="#+id/division1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView android:text="Name :"
android:id="#+id/id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:gravity="left"
android:layout_weight="1"
/>
<EditText android:id="#+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:hint="name"
android:layout_weight="1" />
</LinearLayout>
<View android:id="#+id/division2"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView android:text="Address :"
android:id="#+id/address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:gravity="left"
android:layout_weight="1"
/>
<EditText android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:hint="address"
android:layout_weight="1" />
</LinearLayout>
<View
android:id="#+id/division9"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:text="You Are :"
android:id="#+id/txt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:gravity="left"
android:layout_weight="1" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_weight="1" />
</LinearLayout>
<View
android:id="#+id/division3"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:text="hii"
android:id="#+id/txt4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:gravity="left"
android:layout_weight="1" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_weight="1" />
</LinearLayout>
<View
android:id="#+id/division10"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999" />
<LinearLayout
android:id="#+id/check"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:text="Select your reqirements:-"
android:id="#+id/the"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:gravity="left"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/lay1">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="apple"
android:tag="apple"
android:onClick="onCheckboxClicked" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="banana"
android:tag="banana"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="water_milon"
android:tag="water_milon"
android:onClick="onCheckboxClicked"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/lay2">
<CheckBox
android:id="#+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="guava"
android:tag="guava"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="panir"
android:tag="panir"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:id="#+id/checkBox6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chatni"
android:tag="chatni"
android:onClick="onCheckboxClicked"/>
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/division6"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Write your message(optional) :"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:padding="10dip"
android:layout_marginTop="5dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/edit_text_stle"
android:hint="write something ">
<requestFocus />
</EditText>
<View
android:id="#+id/division7"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#999999"
android:layout_marginTop="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="10dp">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
activity_main.xml is:--
<?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" >
</LinearLayout>
But I can not swipe the page. It is not going to the another page. Why it is happening?
Where is the problem?
Agree with #k3v1n4ud3. Let me just expand a bit since I can't really comment due to lack of karma.
With ViewPager (inside MainActivity.java) + MainFragment (Fragment)+ JoinForm (Fragment), you would be able to get away without having a listener for fling. It would just handle the swiping part automatically for you.
Just think about it like this: You have a brain (MainActivity w/ViewPager) and two arms (the first and second fragment you're implementing).
Create a MainActivity that would contain your ViewPager.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myViewPager = (ViewPager) findViewById(R.id.myViewPager);
//somehow fill the adapter
MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(), getApplicationContext()); //=== required as per the MyAdapter class
//set the adapter
myViewPager.setAdapter(myAdapter);
// display first fragment
myViewPager.setCurrentItem(0);
}
Create an Adapter that extends FragmentPagerAdapter (or FragmentStatePagerAdapter). It looks like this:
class MyAdapter extends FragmentPagerAdapter {
private final int[] titles = {R.string.main_activity_title, R.string.join_activity_title};
private final String[] fragments = {
MainFragment.class.getName(),
JoinFragment.class.getName()
};
private final Context ctx;
public MyAdapter(FragmentManager fm, Context ctx) {
super(fm);
this.ctx = ctx;
}
#Override
public CharSequence getPageTitle(int position) {
return ctx.getString(titles[position]);
}
#Override
public Fragment getItem(int position) {
return Fragment.instantiate(ctx, fragments[position]);
}
#Override
public int getCount() {
return titles.length;
}
}
(Optional) See those title thingys on top of each page, the ones you could click so you could fast forward to the other page? They're called tabhosts.
To use them, simply add a tabhost to your MainActivity layout and add this logic in MainActivity.java:
myViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// when user do a swipe the selected tab change
myTabHost.setSelectedNavigationItem(position);
}
});
//set titles
for (int i = 0; i < myAdapter.getCount(); i++) {
myTabHost.addTab(
myTabHost.newTab()
.setText(myAdapter.getPageTitle(i))
.setTabListener(this)
);
}
4. (Optional) Animations on 'fling'
So to animate when you switch fragments, you simple have to call this:
myViewPager.setPageTransformer(true, new DefaultTransformer());
And you can also customize it to your will.
I apologize if there are typos and other stuff. But this should cover majority of what you need.
You probably should change the architecture, transform your 2 activities into fragment and place them inside a viewPager. The viewPager will handle the sliding part for you.

imageswitcher fills screen (but I dont want it to do that) [android]

I have added an imageswitcher to my register fragment, when the user select his/her gender the image changes but the image shown is too big and I cant scale it. I am using a scrollview and it is not good that the Imageswitcher is bigger than screen. I tried using smaller images but the result is same. Here is my XML:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/registerbackground"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/kayit_kayit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/register"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/kayit_ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/hintAd"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/kayit_soyad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/hintSoyad"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/kayit_email"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/hintEmail"
android:inputType="textEmailAddress"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/kayitKiz"
android:textColor="#FFFFFFFF" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/kayitErkek"
android:textColor="#FFFFFFFF" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageSwitcher
android:id="#+id/cinsiyetSwitcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ImageSwitcher>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/kayit_kelime1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="50dp"
android:hint="#string/hintKelimeler1"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
<EditText
android:id="#+id/kayit_kelime2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/hintKelimeler2"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
<EditText
android:id="#+id/kayit_kelime3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="50dp"
android:hint="#string/hintKelimeler3"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
and the code for the imageswitcher:
....
cinsiyetSwitcher = (ImageSwitcher) rootView.findViewById(R.id.cinsiyetSwitcher);
cinsiyetSwitcher.setFactory(new ViewFactory() {
#Override
public View makeView() {
ImageView imageView = new ImageView(getActivity());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
return imageView;
}
});
kizRadio = (RadioButton) rootView.findViewById(R.id.radio0);
erkekRadio = (RadioButton) rootView.findViewById(R.id.radio1);
kizRadio.setOnClickListener( new View.OnClickListener() {
public void onClick(View v)
{
degistir1(v);
}
});
erkekRadio.setOnClickListener( new View.OnClickListener() {
public void onClick(View v)
{
degistir2(v);
}
});
....
...
public void degistir1(View view)
{
Animation in = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_in_left);
Animation out = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_out_right);
cinsiyetSwitcher.setInAnimation(in);
cinsiyetSwitcher.setOutAnimation(out);
cinsiyetSwitcher.setImageResource(R.drawable.kari);
}
public void degistir2(View view)
{
Animation in = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_out_right);
Animation out = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_in_left);
cinsiyetSwitcher.setInAnimation(out);
cinsiyetSwitcher.setOutAnimation(in);
cinsiyetSwitcher.setImageResource(R.drawable.adam);
}

Categories

Resources