I am trying to show this datas to my recycler view but they are not showed in the recycler view.
My Codes are below
fragment_group_notice.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/GroupNoticeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".groupTab.groupNotices.GroupNoticesFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/groupNoticeListRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager">
</androidx.recyclerview.widget.RecyclerView>
</FrameLayout>
card_group_notice.xml
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/primary_green"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="#+id/NoticeNameCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notice Name"
android:textColor="#color/pure_white"
android:textSize="25sp" />
</LinearLayout>
</layout>
GroupNoticesFragment
class GroupNoticesFragment : Fragment() {
private var _binding: FragmentGroupNoticesBinding? = null
private val binding get() = _binding!!
private lateinit var recycler: RecyclerView
private var adapter: NoticeAdapter?= null
private lateinit var viewModel: NoticeViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
container?.removeAllViews()
_binding = FragmentGroupNoticesBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
recycler = binding.groupNoticeListRecycler
recycler.layoutManager = LinearLayoutManager(context)
recycler.setHasFixedSize(true)
adapter = NoticeAdapter()
recycler.adapter = adapter
viewModel = ViewModelProvider(this)[NoticeViewModel::class.java]
viewModel.allNotices.observe(viewLifecycleOwner) {
adapter!!.updateNoticeList(it)
}
}
}
NoticeAdapter.kt
class NoticeAdapter : RecyclerView.Adapter<NoticeAdapter.NoticeViewHolder>() {
private val notices = ArrayList<GroupNoticeData>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoticeViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(
R.layout.card_group_notices,
parent, false
)
return NoticeViewHolder(itemView)
}
override fun onBindViewHolder(holder: NoticeViewHolder, position: Int) {
val currentNotice = notices[position]
holder.noticeName.text = currentNotice.taskName
}
override fun getItemCount(): Int {
return notices.size
}
fun updateNoticeList(notice: List<GroupNoticeData>) {
this.notices.clear()
this.notices.addAll(notice)
notifyDataSetChanged()
}
class NoticeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val noticeName: TextView = itemView.findViewById(R.id.NoticeNameCard)
}
}
GroupNoticeData
data class GroupNoticeData(
val userId: String,
val taskName: String,
val taskDescription: String,
val taskDate: String,
val path: String?,
val groupId: String
) {
fun toMap(): Map<String, Any?> {
return mapOf(
"userId" to userId,
"taskName" to taskName,
"taskDescription" to taskDescription,
"taskDate" to taskDate,
"path" to path,
"groupId" to groupId
)
}
}
NoticeViewModel
class NoticeViewModel : ViewModel() {
private val repository : NoticeRepo = NoticeRepo().getInstance()
private val _allNotices = MutableLiveData<List<GroupNoticeData>>()
val allNotices : LiveData<List<GroupNoticeData>> = _allNotices
init {
repository.loadNotices(_allNotices)
}
}
NoticeRepo
class NoticeRepo{
val auth = Firebase.auth
val user = auth.currentUser!!.uid
private val noticeReference : DatabaseReference = FirebaseDatabase.getInstance().getReference("groupNotice").child(user)
#Volatile private var INSTANCE : NoticeRepo?= null
fun getInstance(): NoticeRepo {
return INSTANCE ?: synchronized(this) {
val instance = NoticeRepo()
INSTANCE = instance
instance
}
}
fun loadNotices(allNoticeList: MutableLiveData<List<GroupNoticeData>>) {
noticeReference.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
try {
val noticeList : List<GroupNoticeData> = snapshot.children.map { dataSnapshot ->
dataSnapshot.getValue(GroupNoticeData::class.java)!!
}
allNoticeList.postValue(noticeList)
}catch (_: Exception){
}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})
}
}
I tried to change the reference in repo class aslo checked the items height width issue but couldn't come to any solution
There isn't any error but the code is supposed to load data from the rtdb reference but it isn't showing anything. The recycler view was supposed to fill up using the card_group_notice.xml where the information were supposed to come from the database child as you can see groupNotice/(userId)
Related
I'm trying to build a "Note taking" area in my app. I'm having problems with the view binding specifically. i followed this code example "https://codingwithsaud.medium.com/how-to-make-note-app-in-android-studio-part-1-443ccf16921e" to a T, but its mainly built in an activity not a fragment. I'm currently building it in an fragment and everything else is good besides my "Equipment_Tracker.kt" i cant figure out whats going wrong. The list problems take place in the "Equipment_Tracker.kt" Thanks in advance for helping.
List off errors popping up.
Unresolved reference: setContentView
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Type mismatch: inferred type is Equipment_Tracker but Context? was expected
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
None of the following functions can be called with the arguments supplied:
public constructor Intent(p0: Context!, p1: Class<*>!) defined in android.content.Intent
public constructor Intent(p0: String!, p1: Uri!) defined in android.content.Intent
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
Smart cast to 'FragmentEquipmentTrackerBinding' is impossible, because 'binding' is a mutable property that could have been changed by this time
None of the following functions can be called with the arguments supplied:
public open fun makeText(p0: Context!, p1: CharSequence!, p2: Int): Toast! defined in android.widget.Toast
public open fun makeText(p0: Context!, p1: Int, p2: Int): Toast! defined in android.widget.Toast
None of the following functions can be called with the arguments supplied:
public open fun makeText(p0: Context!, p1: CharSequence!, p2: Int): Toast! defined in android.widget.Toast
public open fun makeText(p0: Context!, p1: Int, p2: Int): Toast! defined in android.widget.Toast
Equipment_Tracker.kt
package com.example.armymaintenance
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.armymaintenance.Model.note_model
import com.example.armymaintenance.database.MySqliteHelper
import com.example.armymaintenance.databinding.FragmentEquipmentTrackerBinding
class Equipment_Tracker : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_equipment__tracker, container, false)
}
var binding: FragmentEquipmentTrackerBinding? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = FragmentEquipmentTrackerBinding.inflate(layoutInflater)
setContentView(binding.getRoot())
val helper = MySqliteHelper(this)
binding.btnDisplay.setOnClickListener(View.OnClickListener {
val intent = Intent(this#Equipment_Tracker, Equipment_Tracker::class.java)
startActivity(intent)
})
binding.btnSave.setOnClickListener(View.OnClickListener {
val model = note_model()
model.bumpernumber = binding.bumpernumber.text.toString()
model.description = binding.description.text.toString()
model.nsn = binding.nsn.text.toString()
model.serialnumber = binding.serialnumber.text.toString()
model.date = binding.date.text.toString()
if (model.bumpernumber.isEmpty()) {
binding.bumpernumber.error = "Enter bumper number"
return#OnClickListener
}
if (model.description.isEmpty()) {
binding.description.error = "Enter description"
return#OnClickListener
}
if (model.nsn.isEmpty()) {
binding.nsn.error = "Enter nsn"
return#OnClickListener
}
if (model.serialnumber.isEmpty()) {
binding.serialnumber.error = "Enter serial number"
return#OnClickListener
}
if (model.date.isEmpty()) {
binding.date.error = "Enter date"
return#OnClickListener
}
val r = helper.saveNote(model)
if (r) {
Toast.makeText(this#Equipment_Tracker, "note is saved", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this#Equipment_Tracker, "some thing want wrong", Toast.LENGTH_SHORT)
.show()
}
})
}
}
fragment_equipment_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".Equipment_Tracker">
<LinearLayout
android:layout_centerInParent="true"
android:padding="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/bumpernumber"
android:hint="Bumper Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/description"
android:hint="Enter description"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/nsn"
android:hint="Enter nsn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/serialnumber"
android:hint="Enter serial number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/date"
android:hint="Enter date"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnSave"
android:text="Save"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnDisplay"
android:text="Display"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
note_model.java
package com.example.armymaintenance.Model;
public class note_model {
private int id;
private String bumpernumber;
private String description;
private String nsn;
private String serialnumber;
private String date;
public note_model() {
}
public note_model(int id, String bumpernumber, String description, String nsn, String serialnumber, String date) {
this.id = id;
this.bumpernumber = bumpernumber;
this.description = description;
this.nsn = nsn;
this.serialnumber = serialnumber;
this.date = date;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBumpernumber() {
return bumpernumber;
}
public void setBumpernumber(String bumpernumber) {
this.bumpernumber = bumpernumber;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getNsn() {
return nsn;
}
public void setNsn(String nsn) {
this.nsn = nsn;
}
public String getSerialnumber() {
return serialnumber;
}
public void setSerialnumber(String serialnumber) {
this.serialnumber = serialnumber;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
MySqliteHelper.java
package com.example.armymaintenance.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
import com.example.armymaintenance.Model.note_model;
import java.util.ArrayList;
import java.util.List;
public class MySqliteHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="note.db";
private static final int VERSION=1;
public MySqliteHelper(#Nullable Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
#Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String table1="create table "+TableSchema.note.TABLE_NAME+"("+TableSchema.note.ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+TableSchema.note.BUMPERNUMBER+" TEXT, "+TableSchema.note.DESCRIPTION+" TEXT,"+TableSchema.note.NSN+" TEXT,"+TableSchema.note.SERIALNUMBER+" TEXT, "+TableSchema.note.DATE+" TEXT );";
sqLiteDatabase.execSQL(table1);
}
public boolean saveNote(note_model model){
SQLiteDatabase database=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(TableSchema.note.BUMPERNUMBER,model.getBumpernumber());
cv.put(TableSchema.note.DESCRIPTION,model.getDescription());
cv.put(TableSchema.note.NSN,model.getNsn());
cv.put(TableSchema.note.SERIALNUMBER,model.getSerialnumber());
cv.put(TableSchema.note.DATE,model.getDate());
long id= database.insert(TableSchema.note.TABLE_NAME,null,cv);
if (id==-1){
return false;
}
return true;
}
public List<note_model> getAllNotes(){
SQLiteDatabase database= this.getReadableDatabase();
String[] cols={TableSchema.note.ID,TableSchema.note.BUMPERNUMBER,TableSchema.note.DESCRIPTION,TableSchema.note.NSN,TableSchema.note.SERIALNUMBER,TableSchema.note.DATE};
Cursor cursor=database.query(TableSchema.note.TABLE_NAME,cols,null,null,null,null,TableSchema.note.ID+" DESC");
ArrayList<note_model> list=new ArrayList<>();
while (cursor.moveToNext()){
note_model model=new note_model();
model.setId(cursor.getInt(cursor.getColumnIndex(TableSchema.note.ID)));
model.setBumpernumber(cursor.getString(cursor.getColumnIndex(TableSchema.note.BUMPERNUMBER)));
model.setDescription(cursor.getString(cursor.getColumnIndex(TableSchema.note.DESCRIPTION)));
model.setNsn(cursor.getString(cursor.getColumnIndex(TableSchema.note.NSN)));
model.setSerialnumber(cursor.getString(cursor.getColumnIndex(TableSchema.note.SERIALNUMBER)));
model.setDate(cursor.getString(cursor.getColumnIndex(TableSchema.note.DATE)));
list.add(model);
}
cursor.close();
database.close();
return list;
}
#Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
if (i<i1){
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "+TableSchema.note.TABLE_NAME);
}
}
}
TableSchema.java
package com.example.armymaintenance.database;
public class TableSchema {
public static class note{
public static final String TABLE_NAME="tbl_note";
public static final String ID="id";
public static final String BUMPERNUMBER="bumpernumber";
public static final String DESCRIPTION="description";
public static final String NSN="nsn";
public static final String SERIALNUMBER="serialnumber";
public static final String DATE="date";
}
}
Binding is wrong Please check this documentation for the view Binding
https://developer.android.com/topic/libraries/view-binding#kts
In Activity you can initialize the lateinit var binding: ActivityMainBinding
and can inflate the view like this
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
But for the fragments the way is different
private var _binding: FragmentMainBinding? = null
private val binding get() = _binding!!
and in onCreateView method you have to do it like this
_binding = FragmentMainBinding.inflate(inflater, container, false)
val view = binding.root
return view
Please make sure that you do it in onCreateView not in onViewCreated
and in onDestroyView you have to set its value to null
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
That is the Proper way of doing binding you can also visit the documentation for more information
We are using picker control our app. I want to customize the picker while clicking the dropdown popup list will be shown. In that popup, I want to display the left side icon with the text. How could be achieve using xamarin forms picker android and ios platform?
You could use CustomRenderer to achieve this.
Here is a sample:
Create a custom picker:
public class MyPicker : Picker
{
}
For Android:
Create a custom renderer in Android:
public class CustomPicker : PickerRenderer
{
private Dialog dialog;
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
Control.Click += Control_Click1;
}
protected override void Dispose(bool disposing)
{
Control.Click -= Control_Click1;
base.Dispose(disposing);
}
private void Control_Click1(object sender, EventArgs e)
{
//throw new NotImplementedException();
Picker model = Element;
dialog = new Dialog(Forms.Context);
dialog.SetContentView(Resource.Layout.custom_picker_dialog);
Android.Widget.ListView listView = (Android.Widget.ListView)dialog.FindViewById(Resource.Id.listview);
//listView.Adapter = new CustomPickerAdapter(((List<PickerModel>)model.ItemsSource), model.SelectedIndex);
listView.Adapter = new MyAdaptr((List<string>)model.ItemsSource);
listView.ItemClick += (object sender1, ItemClickEventArgs e1) =>
{
Element.SelectedIndex = e1.Position;
dialog.Hide();
};
if (model.ItemsSource.Count > 3)
{
var height = Xamarin.Forms.Application.Current.MainPage.Height;
var width = Xamarin.Forms.Application.Current.MainPage.Width;
dialog.Window.SetLayout(700, 800);
}
dialog.Show();
}
class MyAdaptr : BaseAdapter
{
private IList<string> mList;
public MyAdaptr(IList<string> itemsSource)
{
mList = itemsSource;
}
public override int Count => mList.Count;
public override Java.Lang.Object GetItem(int position)
{
return mList[position];
}
public override long GetItemId(int position)
{
return position;
}
public override Android.Views.View GetView(int position, Android.Views.View convertView, ViewGroup parent)
{
Android.Views.View view = convertView;
convertView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.celllayout, null); //here is the style you want to achieve
TextView text = convertView.FindViewById<TextView>(Resource.Id.textview1);
text.Text = mList[position];
return convertView;
}
}
}
custom_picker_dialog.axml:
<?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:gravity="center"
>
<TextView
android:text="Select One Option"
android:layout_width="200dp"
android:layout_height="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"/>
<ListView
android:id="#+id/listview"
android:layout_gravity="center"
android:background="#drawable/abc_list_pressed_holo_light"
android:layout_width="match_parent"
android:dividerHeight="3dp"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
</LinearLayout>
celllayout.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="#+id/img"
android:src="xxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
For ios:
Create a custom renderer in ios
public class CustomPicker : PickerRenderer
{
List<string> itemList;
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
Picker myPicker = Element;
itemList = myPicker.Items.ToList();
UITextField textField = Control;
UIPickerView pickerView = textField.InputView as UIPickerView;
pickerView.Delegate = new MyPickerViewDelegate(itemList,Control);
textField.InputView = pickerView;
var toolbar = new UIToolbar(new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width , 1)) { BarStyle = UIBarStyle.Default, Translucent = true };
textField.InputAccessoryView = toolbar;
}
}
internal class MyPickerViewDelegate : UIPickerViewDelegate
{
private List<string> itemList;
private UITextField textField;
public MyPickerViewDelegate(List<string> itemList, UITextField control)
{
this.itemList = itemList;
this.textField = control;
}
//Define the Font size or style
public override NSAttributedString GetAttributedTitle(UIPickerView pickerView, nint row, nint component)
{
var text = new NSAttributedString(
itemList[(int)row],
font: UIFont.SystemFontOfSize(24),
foregroundColor: UIColor.Red,
strokeWidth: 4
);
return text;
}
//Define the row height
public override nfloat GetRowHeight(UIPickerView pickerView, nint component)
{
return 45;
}
//define the itemview in your listview,you could add a UIImage here for your scene
public override UIView GetView(UIPickerView pickerView, nint row, nint component, UIView view)
{
UIView contentView = new UIView(new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, 45));
UILabel label = new UILabel();
label.Frame = contentView.Bounds;
contentView.AddSubview(label);
label.Text = itemList[(int)row];
return contentView;
}
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
//base.Selected(pickerView, row, component);
textField.Text = itemList[(int)row];
textField.ResignFirstResponder();
}
}
Finally you could use in your page.xaml like:
<local:MyPicker x:Name="picker" Title="Select An option" />
Im having trouble getting my fragments to run, and im getting the following exception. MVVM Cross Exception: Cannot Create Fragment. Use the MvxAppCompatViewPresenter when using Android Support Fragments.
Here is the MainViewModel, where it should navigate to the first fragment/ViewModel (ActionViewModel).
public class MainViewModel : BaseViewModel
{
public IMvxCommand<string> BottomNavigationItemSelectedCommand { get; private set; }
List<TabViewModel> _tabs;
public List<TabViewModel> Tabs
{
get => _tabs;
set => SetProperty(ref _tabs, value);
}
private readonly IMvxNavigationService _navigationService;
public MainViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
BottomNavigationItemSelectedCommand = new MvxCommand<string>(BottomNavigationItemSelected);
var tabs = new List<TabViewModel>
{
Mvx.IoCProvider.IoCConstruct<ActionViewModel>(),
Mvx.IoCProvider.IoCConstruct<TaskViewModel>(),
Mvx.IoCProvider.IoCConstruct<KpiViewModel>(),
Mvx.IoCProvider.IoCConstruct<EisViewModel>(),
Mvx.IoCProvider.IoCConstruct<MenuViewModel>()
};
Tabs = tabs;
}
public override Task Initialize()
{
return base.Initialize();
}
// Android-only, not used on iOS
private void BottomNavigationItemSelected(string tabId)
{
if (tabId == null)
{
return;
}
foreach (var item in Tabs)
{
if (tabId == item.TabId)
{
_navigationService.Navigate(item);
break;
}
}
}
}
}
And this is the ActionFragment:
[MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.fragment_content, true)]
[Register(nameof(ActionFragment))]
public class ActionFragment : BaseFragment<ActionViewModel>
{
//public static ActionFragment NewInstance() => new ActionFragment();
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.activity_actions, container, false);
return view;
}
}
This is the main activity layout:
<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/parentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.ContentFrameLayout
android:id="#+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
app:menu="#menu/bottom_nav_menu"
local:MvxBind="BottomNavigationSelectedBindingKey BottomNavigationItemSelectedCommand"/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Could someone please let me know what I should do to solve this problem? I am new to this!
I found out that my problem was that I had to change the MainApplication.cs and Setup.cs classes.
from :
public class Setup : MvxAndroidSetup
to
public class Setup : MvxAppCompatSetup<App>
and from :
public class MainApplication : MvxAndroidApplication<MvxAndroidSetup<App>, App>
to
public class MainApplication : MvxAppCompatApplication<Setup, App>
I am new to Mobile development. I have started my Mobile app with Kotlin. I have an Activity (ProductsActivity.kt) which loads RecyclerView with ImageView and TextView getting data from MySQL, which is working independently. Now, I want this Activity to load in Fragment, I tried to load using Inflater, but it doesn't show any data. Following is my code, please help how can I achieve the same. Thanks in advance.
MainActivity.kt
package com.example.administrator.zmaart
import android.content.Intent
import android.os.Bundle
import android.support.design.widget.NavigationView
import android.support.v4.app.Fragment
import android.support.v4.view.GravityCompat
import android.support.v4.widget.DrawerLayout
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Toast
class MainActivity : AppCompatActivity(),
NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar = findViewById<View>(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
val drawer = findViewById<View>(R.id.drawer_layout) as DrawerLayout
val toggle = ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close)
drawer.addDrawerListener(toggle)
toggle.syncState()
val navigationView = findViewById<View>(R.id.nav_view) as
NavigationView
navigationView.setNavigationItemSelectedListener(this)
displaySelectedScreen(R.id.nav_home)
}
private var backButtonCount: Int = 0
override fun onBackPressed() {
val drawer = findViewById<View>(R.id.drawer_layout) as DrawerLayout
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START)
} else {
if (backButtonCount >= 1) {
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_HOME)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
} else {
Toast.makeText(this, "Press the back button once again to close the application.", Toast.LENGTH_SHORT).show()
backButtonCount++
}
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
val id = item.itemId
return if (id == R.id.action_settings) {
true
} else super.onOptionsItemSelected(item)
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
displaySelectedScreen(item.itemId)
return true
}
private fun displaySelectedScreen(itemId: Int) {
//creating fragment object
var fragment: Fragment? = null
//initializing the fragment object which is selected
when (itemId) {
R.id.nav_home -> fragment = home()
R.id.nav_orders -> fragment = orders()
R.id.nav_wishlist -> {
val intent = Intent(this#MainActivity,
ProductsActivity::class.java)
this#MainActivity.startActivity(intent)
}
R.id.nav_logout -> {
val sharedPreferences = getSharedPreferences("SharedPref", 0)
val editor = sharedPreferences.edit()
editor.clear()
editor.apply()
val intent = Intent(this#MainActivity, Login_Page::class.java)
this#MainActivity.startActivity(intent)
}
}
//replacing the fragment
if (fragment != null) {
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.content_frame, fragment)
ft.commit()
}
val drawer = findViewById<View>(R.id.drawer_layout) as DrawerLayout
drawer.closeDrawer(GravityCompat.START)
}
}
activity_products.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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=".ProductsActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recylcerView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="745dp"
tools:layout_editor_absoluteY="-51dp" />
</RelativeLayout>
ProductsActivity.kt
package com.example.administrator.zmaart
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import org.json.JSONArray
import org.json.JSONException
import java.util.*
class ProductsActivity : AppCompatActivity() {
private lateinit var productList: MutableList<Product>
private lateinit var recyclerView: RecyclerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_products)
recyclerView = findViewById(R.id.recylcerView1)
recyclerView.setHasFixedSize(false)
recyclerView.layoutManager = LinearLayoutManager(this)
productList = ArrayList()
loadProducts()
}
private fun loadProducts() {
/*
* Creating a String Request
* The request type is GET defined by first parameter
* The URL is defined in the second parameter
* Then we have a Response Listener and a Error Listener
* In response listener we will get the JSON response as a String
* */
val stringRequest = StringRequest(Request.Method.GET, URL_PRODUCTS,
Response.Listener { response ->
try {
//converting the string to json array object
val array = JSONArray(response)
//traversing through all the object
for (i in 0 until array.length()) {
//getting product object from json array
val product = array.getJSONObject(i)
//adding the product to product list
productList.add(Product(
product.getString("prod_id_sha"),
product.getString("prod_title"),
product.getDouble("prod_price"),
product.getDouble("prod_price2"),
product.getString("img_thumbnail")
))
}
//creating adapter object and setting it to recyclerview
val adapter = ProductsAdapter(this#ProductsActivity, productList)
recyclerView.adapter = adapter
} catch (e: JSONException) {
e.printStackTrace()
}
},
Response.ErrorListener { })
//adding our stringrequest to queue
Volley.newRequestQueue(this).add(stringRequest)
}
companion object {
//this is the JSON Data URL
//make sure you are using the correct ip else it will not work
private const val URL_PRODUCTS = "localhost/app/load_prod.php"
}
}
home.kt (where I want to load activity_products.xml)
package com.example.administrator.zmaart
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class home : Fragment() {
private lateinit var productList: MutableList<Product>
private lateinit var recyclerView: RecyclerView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.activity_products, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity!!.title = "Home"
}
}
Please let me know if any other code(s) to be included to help you to help me.
If i have to 2 tabs inside ViewPager.and each tab have it's own fragment associated with it.if the fragments of respective tabs have ScrollView as MainView .if i scrolldown the layout of first tab and move to second tab and again swipe back to first it is in same scrolled state as i left it.
So How can i get the scroll automaticaly to the top when i click or swipe to tab.
i have tried Scrollview.fullScroll(View.FOCUS_UP); and Scrollview.scrollTo(0,0);
ViewPagerAdapter.java
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
private int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
public ViewPagerAdapter (FragmentManager fm, CharSequence mTitles[], int mNumbOfTabsumb) {
super(fm);
this.Titles = mTitles;
this.NumbOfTabs = mNumbOfTabsumb;
}
#Override
public Fragment getItem(int position) {
if(position == 0) // if the position is 0 we are returning the First tab
{
Tab_1 tab1 = new Tab_1();
return tab1;
}
else // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab
{
Tab_2 tab2 = new Tab_2();
return tab2;
}
}
#Override
public CharSequence getPageTitle(int position)
{
return Titles[position];
}
#Override
public int getCount() {
return NumbOfTabs;
}}
SlidingTabLayout.java
public class SlidingTabLayout extends HorizontalScrollView {
public interface TabColorizer {
int getIndicatorColor(int position);
}
public interface TabIconProvider {
int getPageIconResId(int position);
}
private static final int TITLE_OFFSET_DIPS = 24;
private static final int TAB_VIEW_PADDING_DIPS = 16;
private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
private int mTitleOffset;
private int mTabViewLayoutId;
private int mTabViewTextViewId;
private boolean mDistributeEvenly;
private ViewPager mViewPager;
private SparseArray<String> mContentDescriptions = new SparseArray<String>();
private ViewPager.OnPageChangeListener mViewPagerPageChangeListener;
private final SlidingTabStrip mTabStrip;
public SlidingTabLayout(Context context) {
this(context, null);
}
public SlidingTabLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Disable the Scroll Bar
setHorizontalScrollBarEnabled(false);
// Make sure that the Tab Strips fills this View
setFillViewport(true);
mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
mTabStrip = new SlidingTabStrip(context);
addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
/**
* Set the custom {#link //com.google.samples.apps.iosched.ui.widget.SlidingTabLayout.TabColorizer} to be used.
*
* If you only require simple custmisation then you can use
* {#link #setSelectedIndicatorColors(int...)} to achieve
* similar effects.
*/
public void setCustomTabColorizer(TabColorizer tabColorizer) {
mTabStrip.setCustomTabColorizer(tabColorizer);
}
public void setDistributeEvenly(boolean distributeEvenly) {
mDistributeEvenly = distributeEvenly;
}
/**
* Sets the colors to be used for indicating the selected tab. These colors are treated as a
* circular array. Providing one color will mean that all tabs are indicated with the same color.
*/
public void setSelectedIndicatorColors(int... colors) {
mTabStrip.setSelectedIndicatorColors(colors);
}
public void setTitleTextColor(int color) {
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
if (mTabStrip.getChildAt(i) != null && TextView.class.isInstance(mTabStrip.getChildAt(i))) {
((TextView) mTabStrip.getChildAt(i)).setTextColor(color);
}
}
}
/**
* Set the {#link ViewPager.OnPageChangeListener}. When using {#link //com.google.samples.apps.iosched.ui.widget.SlidingTabLayout} you are
* required to set any {#link ViewPager.OnPageChangeListener} through this method. This is so
* that the layout can update it's scroll position correctly.
*
* #see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
*/
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
mViewPagerPageChangeListener = listener;
}
/**
* Set the custom layout to be inflated for the tab views.
*
* #param layoutResId Layout id to be inflated
* #param textViewId id of the {#link TextView} in the inflated view
*/
public void setCustomTabView(int layoutResId, int textViewId) {
mTabViewLayoutId = layoutResId;
mTabViewTextViewId = textViewId;
}
/**
* Sets the associated view pager. Note that the assumption here is that the pager content
* (number of tabs and tab titles) does not change after this call has been made.
*/
public void setViewPager(ViewPager viewPager) {
mTabStrip.removeAllViews();
mViewPager = viewPager;
if (viewPager != null) {
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
private int mScrollState;
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int tabStripChildCount = mTabStrip.getChildCount();
if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
return;
}
mTabStrip.onViewPagerPageChanged(position, positionOffset);
View selectedTitle = mTabStrip.getChildAt(position);
int extraOffset = (selectedTitle != null)
? (int) (positionOffset * selectedTitle.getWidth())
: 0;
scrollToTab(position, extraOffset);
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageScrolled(position, positionOffset,
positionOffsetPixels);
}
}
#Override
public void onPageSelected(int position) {
if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
mTabStrip.onViewPagerPageChanged(position, 0f);
scrollToTab(position, 0);
}
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
mTabStrip.getChildAt(i).setSelected(position == i);
}
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageSelected(position);
}
}
#Override
public void onPageScrollStateChanged(int state) {
mScrollState = state;
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageScrollStateChanged(state);
}
}
});;
populateTabStrip();
}
}
/**
* Create a default view to be used for tabs. This is called if a custom tab view is not set via
* {#link #setCustomTabView(int, int)}.
*/
protected TextView createDefaultTabView(Context context) {
TextView textView = new TextView(context);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
textView.setAllCaps(true);
}
int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
textView.setPadding(padding, padding, padding, padding);
return textView;
}
private void populateTabStrip()
{
final PagerAdapter adapter = mViewPager.getAdapter();
final OnClickListener tabClickListener = new TabClickListener();
for (int i = 0; i < adapter.getCount(); i++) {
View tabView = null;
TextView tabTitleView = null;
if (mTabViewLayoutId != 0) {
// If there is a custom tab view layout id set, try and inflate it
tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
false);
tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
}
if (tabView == null) {
tabView = createDefaultTabView(getContext());
}
if (tabTitleView == null && TextView.class.isInstance(tabView)) {
tabTitleView = (TextView) tabView;
}
if (mDistributeEvenly) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
lp.width = 0;
lp.weight = 1;
}
tabTitleView.setText(adapter.getPageTitle(i));
tabView.setOnClickListener(tabClickListener);
String desc = mContentDescriptions.get(i, null);
if (desc != null) {
tabView.setContentDescription(desc);
}
mTabStrip.addView(tabView);
if (i == mViewPager.getCurrentItem()) {
tabView.setSelected(true);
}
tabTitleView.setTextColor(getResources().getColorStateList(R.color.colorAccent));
tabTitleView.setTextSize(14);
}
}
public void setContentDescription(int i, String desc) {
mContentDescriptions.put(i, desc);
}
#Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mViewPager != null) {
scrollToTab(mViewPager.getCurrentItem(), 0);
}
}
private void scrollToTab(int tabIndex, int positionOffset) {
final int tabStripChildCount = mTabStrip.getChildCount();
if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
return;
}
View selectedChild = mTabStrip.getChildAt(tabIndex);
if (selectedChild != null) {
int targetScrollX = selectedChild.getLeft() + positionOffset;
if (tabIndex > 0 || positionOffset > 0) {
// If we're not at the first child and are mid-scroll, make sure we obey the offset
targetScrollX -= mTitleOffset;
}
scrollTo(targetScrollX, 0);
}
}
private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
private int mScrollState;
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int tabStripChildCount = mTabStrip.getChildCount();
if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
return;
}
mTabStrip.onViewPagerPageChanged(position, positionOffset);
View selectedTitle = mTabStrip.getChildAt(position);
int extraOffset = (selectedTitle != null)
? (int) (positionOffset * selectedTitle.getWidth())
: 0;
scrollToTab(position, extraOffset);
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageScrolled(position, positionOffset,
positionOffsetPixels);
}
}
#Override
public void onPageScrollStateChanged(int state) {
mScrollState = state;
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageScrollStateChanged(state);
}
}
#Override
public void onPageSelected(int position) {
if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
mTabStrip.onViewPagerPageChanged(position, 0f);
scrollToTab(position, 0);
}
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
mTabStrip.getChildAt(i).setSelected(position == i);
}
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageSelected(position);
}
}
}
private class TabClickListener implements OnClickListener {
#Override
public void onClick(View v) {
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
if (v == mTabStrip.getChildAt(i)) {
mViewPager.setCurrentItem(i);
return;
}
}
}
}
}
MainActivity.java
public class MainActivityextends AppCompatActivity {
private ViewPager pager;
private ViewPagerAdapter adapter;
private SlidingTabLayout tabs;
private CharSequence Titles[]={"Tab_1","Tab_2"};
private int Numboftabs =2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
#Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);
}}
activity_main.xml
<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"
android:orientation="vertical"
tools:context="com.AndroidApp.ActivityPackage.MainActivity">
<com.AndroidApp.SlidingTab.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tabColor"
android:elevation="2dp" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1" />
</LinearLayout>
tab_1.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/srlview"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/edt_empnum"
android:inputType="number"
android:layout_gravity="center"
android:hint="Enter Employee Number"
style="#style/spinner_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp" />
<EditText
android:id="#+id/edt_empname"
style="#style/spinner_style"
android:layout_gravity="center"
android:hint="Enter Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp" />
<EditText
android:id="#+id/edt_empdob"
android:inputType="date"
style="#style/spinner_style"
android:layout_gravity="center"
android:hint="Enter Birthdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp" />
<Spinner
android:id="#+id/spinner_empType"
android:layout_gravity="center"
style="#style/spinner_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"/>
<EditText
android:id="#+id/edt_empQuery"
style="#style/spinner_style"
android:inputType="textMultiLine"
android:lines="3"
android:minLines="3"
android:maxLines="8"
android:gravity="top|start"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Enter Query"
android:scrollbars="vertical"
android:layout_margin="5dp"
android:padding="5dp"/>
<EditText
android:id="#+id/edt_empcontact"
style="#style/spinner_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_gravity="center"
android:inputType="number"
android:hint="Enter Contact Number"
android:padding="5dp" />
<EditText
android:id="#+id/edt_empemailid"
style="#style/spinner_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_gravity="center"
android:inputType="number"
android:hint="Enter Email Id"
android:padding="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:padding="5dp"
android:gravity="center">
<Button android:id="#+id/btn__emp_postQuery"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="SUBMIT"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:background="#color/colorPrimary"
android:layout_marginRight="10dp" />
<Button android:id="#+id/btn_corpempquery_emp_resetQuery"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="RESET"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:background="#color/colorPrimary"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Tab_1.java
public class Tab_1 extends Fragment {
private View rootView;
public Tab_1()
{
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.tab_1,container,false);
return rootView;
}
}
Tab_2.java and tab_2.xml are quite same as that of Tab_1 and tab_1 respectively.
Please help. Thank you.