added button functionality in home fragment
This commit is contained in:
		
							parent
							
								
									229df6047a
								
							
						
					
					
						commit
						78faae6042
					
				
							
								
								
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="VcsDirectoryMappings"> | ||||||
|  |     <mapping directory="$PROJECT_DIR$" vcs="Git" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
| @ -3,6 +3,7 @@ package com.ploedige.navdrawertest; | |||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.Menu; | import android.view.Menu; | ||||||
|  | import android.widget.Toast; | ||||||
| 
 | 
 | ||||||
| import com.google.android.material.floatingactionbutton.FloatingActionButton; | import com.google.android.material.floatingactionbutton.FloatingActionButton; | ||||||
| import com.google.android.material.snackbar.Snackbar; | import com.google.android.material.snackbar.Snackbar; | ||||||
| @ -60,4 +61,5 @@ public class MainActivity extends AppCompatActivity { | |||||||
|         return NavigationUI.navigateUp(navController, mAppBarConfiguration) |         return NavigationUI.navigateUp(navController, mAppBarConfiguration) | ||||||
|                 || super.onSupportNavigateUp(); |                 || super.onSupportNavigateUp(); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
| @ -4,7 +4,9 @@ import android.os.Bundle; | |||||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
|  | import android.widget.Button; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
|  | import android.widget.Toast; | ||||||
| 
 | 
 | ||||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||||
| import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||||
| @ -23,11 +25,11 @@ public class HomeFragment extends Fragment { | |||||||
|         homeViewModel = |         homeViewModel = | ||||||
|                 new ViewModelProvider(this).get(HomeViewModel.class); |                 new ViewModelProvider(this).get(HomeViewModel.class); | ||||||
|         View root = inflater.inflate(R.layout.fragment_home, container, false); |         View root = inflater.inflate(R.layout.fragment_home, container, false); | ||||||
|         final TextView textView = root.findViewById(R.id.text_home); |         Button toast_btn = (Button) root.findViewById(R.id.toast_btn); | ||||||
|         homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { |         toast_btn.setOnClickListener(new View.OnClickListener() { | ||||||
|             @Override |             @Override | ||||||
|             public void onChanged(@Nullable String s) { |             public void onClick(View v) { | ||||||
|                 textView.setText(s); |                Toast.makeText(getActivity(),"Test Toast",Toast.LENGTH_SHORT).show(); | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|         return root; |         return root; | ||||||
|  | |||||||
| @ -6,17 +6,14 @@ | |||||||
|     android:layout_height="match_parent" |     android:layout_height="match_parent" | ||||||
|     tools:context=".ui.home.HomeFragment"> |     tools:context=".ui.home.HomeFragment"> | ||||||
| 
 | 
 | ||||||
|     <TextView |     <Button | ||||||
|         android:id="@+id/text_home" |         android:id="@+id/toast_btn" | ||||||
|         android:layout_width="match_parent" |         android:text="Toast" | ||||||
|  | 
 | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|         android:layout_height="wrap_content" |         android:layout_height="wrap_content" | ||||||
|         android:layout_marginStart="8dp" |         app:layout_constraintLeft_toLeftOf="parent" | ||||||
|         android:layout_marginTop="8dp" |         app:layout_constraintRight_toRightOf="parent" | ||||||
|         android:layout_marginEnd="8dp" |         app:layout_constraintTop_toTopOf="parent" | ||||||
|         android:textAlignment="center" |         app:layout_constraintBottom_toBottomOf="parent"/> | ||||||
|         android:textSize="20sp" |  | ||||||
|         app:layout_constraintBottom_toBottomOf="parent" |  | ||||||
|         app:layout_constraintEnd_toEndOf="parent" |  | ||||||
|         app:layout_constraintStart_toStartOf="parent" |  | ||||||
|         app:layout_constraintTop_toTopOf="parent" /> |  | ||||||
| </androidx.constraintlayout.widget.ConstraintLayout> | </androidx.constraintlayout.widget.ConstraintLayout> | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user