I know that there are a lot of question like this, but i can't find one that can help me. Please pay no attention at strings that are hard coded or other things like that, i will fix. I don't see anything wrong in adapter class or in the fragments. I use Disco class for fill a place list, the Place class contains all the methods that after i use in the adapter.Can anyone help me please? Thank you.
Class MainActivity
package com.techmind.tourguideapp;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager manager = getSupportFragmentManager();
ViewPager pager = findViewById(R.id.tourPager);
pager.setAdapter(new FragmentAdapter(manager));
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(pager);
}
}
class Disco
package com.techmind.tourguideapp;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Nahuel on 31.05.2018.
*/
public class Disco {
public static ArrayList<Places> initDiscoList(ArrayList<Places> places) {
places.add(new Places().
setAddress("via a").
setImage(1).
setName("casino").
setPhone("333").
setPrice("20€").
setHour("10:30"));
return places;
}
}
Class DiscoFragment
package com.techmind.tourguideapp;
import android.support.v4.app.Fragment;
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Nahuel on 31.05.2018.
*/
public class DiscoFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ArrayList<Places> list = new ArrayList<>();
list = Disco.initDiscoList(list);
PlacesAdapter adapter = new PlacesAdapter(getActivity(), list);
View view = inflater.inflate(R.layout.row_item, container, false);
ListView listView = (ListView) view.findViewById(R.id.list_items);
listView.setAdapter(adapter);
return view;
}
}
Class FragmentAdapter
package com.techmind.tourguideapp;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
/**
* Created by Nahuel on 31.05.2018.
*/
public class FragmentAdapter extends FragmentPagerAdapter {
public FragmentAdapter (FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return new DiscoFragment();
}
#Override
public int getCount() {
return 3;
}
public CharSequence getPageTitle(int position) {
return "Gradara";
}
}
Class Places
package com.techmind.tourguideapp;
/**
* Created by Nahuel on 31.05.2018.
*/
public class Places {
private String name;
private String price;
private String phone;
private String Address;
private String hour;
private int image;
private final int NO_IMAGE = -1;
public Places () {
}
public String getHour() {
return hour;
}
public String getName() {
return name;
}
public String getPrice() {
return price;
}
public String getPhone() {
return phone;
}
public String getAddress() {
return Address;
}
public int getImage() {
return image;
}
public Places setName(String name) {
this.name = name;
return this;
}
public Places setHour(String hour) {
this.hour = hour;
return this;
}
public Places setPrice(String price) {
this.price = price;
return this;
}
public Places setPhone(String phone) {
this.phone = phone;
return this;
}
public Places setAddress(String address) {
Address = address;
return this;
}
public Places setImage(int image) {
this.image = image;
return this;
}
}
Class PlaceAdapter
package com.techmind.tourguideapp;
import android.content.Context;
import android.location.Location;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class PlacesAdapter extends ArrayAdapter<Places> {
public PlacesAdapter(Context context, List<Places> places) {
super(context,-1, places);
}
public View getView (int position, ViewGroup parent, View convertView) {
View listView = convertView;
Places place = getItem(position);
if(listView == null) {
listView = LayoutInflater.from(getContext()).inflate(
R.layout.row_item, parent, false);
}
TextView location = listView.findViewById(R.id.locationName);
location.setText("casino");
TextView hour = listView.findViewById(R.id.txthour);
hour.setText("aaa");
TextView address = listView.findViewById(R.id.address);
address.setText("aaaaa");
TextView price = listView.findViewById(R.id.txtmoney);
price.setText("aaaaa");
TextView phone = listView.findViewById(R.id.phone);
phone.setText("aaaaa");
ImageView img = listView.findViewById(R.id.imgRow);
img.setImageResource(R.drawable.ic_launcher_background);
return listView;
}
}
Activity_Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.techmind.tourguideapp.MainActivity">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
/>
<android.support.v4.view.ViewPager
android:id="#+id/tourPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
List_item.xml
</LinearLayout>
<?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">
<ListView
android:id="#+id/list_items"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Row_item.xml
<?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">
<ImageView
android:id="#+id/imgRow"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/gradara" />
<TextView
android:id="#+id/locationName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="24sp"
android:textStyle="bold"
android:text=""/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.5">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/positionIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/position"
android:layout_alignParentStart="true"/>
<TextView
android:id="#+id/txtPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/positionIcon"
android:layout_marginTop="5dp"
android:text="" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/positionIcon"
android:layout_toRightOf="#id/positionIcon"
android:text="" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/moneyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/money"
android:layout_alignParentStart="true"/>
<TextView
android:id="#+id/txtmoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/moneyIcon"
android:layout_marginTop="15dp"
android:text="10€ - 20€" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/hourIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/hour"
android:layout_alignParentStart="true"/>
<TextView
android:id="#+id/txthour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/hourIcon"
android:layout_marginTop="15dp"
android:text="09:30 - 23:00" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone:"
android:layout_marginEnd="5dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3334323560"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You said you got a null pointer on set adapter. Are you talking about
this line in file DiscoFragment?
listView.setAdapter(adapter)
if listView is null then the findViewByID didn't find a view. Or maybe something inside adapter is null. It is hard to tell from what you said.
i found the error in
ArrayList<Places> list = new ArrayList<>();
list = Disco.initDiscoList(list);
PlacesAdapter adapter = new PlacesAdapter(getActivity(), list);
View view = inflater.inflate(R.layout.row_item, container, false);
ListView listView = (ListView) view.findViewById(R.id.list_items);
listView.setAdapter(adapter);
return view;
}
When i use the inflate method the first parameter was wrong, i used the layout of the row instead of the listView layout.
Thank you for your answers, next times i will post logs and less useless code :)
Related
I am building a social media app, and I wanted to add story scroll view. The problem I am facing is my recycler view is showing only two items however I gave it 4 or more.
I am using horizontal scroll view because I have a first item that says "click to add story" which is different than those items in recycler view. I am new in android building so any help would be appreciated, and I checked different solutions but none were helpful. The only success I got was to increase layout-width of recycler view to 1000dp that helps in scrolling but that's not efficient. My home fragment code, where problem is occurred:
<HorizontalScrollView
android:id="#+id/horizontal_story_scroll_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:isScrollContainer="true"
android:paddingLeft="5dp"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbars="none"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="120dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="160dp"
android:layout_height="match_parent"
android:paddingRight="5dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/click_add_story_img_id"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:src="#drawable/rain_drops_bg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:riv_border_color="#333333"
app:riv_border_width="2dip"
app:riv_corner_radius="20dip"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat" />
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/user_story_img_id"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/black_shade"
app:background="#color/light_red"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/click_add_story_img_id"
app:layout_constraintStart_toStartOf="#+id/click_add_story_img_id"
app:layout_constraintTop_toTopOf="parent"
app:riv_border_color="#333333"
app:riv_border_width="2dip"
app:riv_corner_radius="20dip"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/add_story"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:padding="5dp"
android:src="#drawable/add_3_icon"
app:layout_constraintBottom_toTopOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/click_add_story_img_id" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:fontFamily="#font/baloo_bhai"
android:text="Click to add Story"
android:textColor="#color/white"
app:layout_constraintBottom_toTopOf="#+id/click_add_story_img_id"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/add_story" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/story_rv_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>
My Adapter:
package com.assadcoorp.socialstar.Package;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.assadcoorp.socialstar.DataTypes.StoryDataType;
import com.assadcoorp.socialstar.R;
import java.util.ArrayList;
public class StoryAdapter extends RecyclerView.Adapter<StoryAdapter.viewHolder>{
ArrayList<StoryDataType> list;
Context context;
public StoryAdapter(ArrayList<StoryDataType> list, Context context) {
this.list = list;
this.context = context;
}
#NonNull
#Override
public viewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.sample_story,parent,false);
return new viewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull viewHolder holder, int position) {
StoryDataType model=list.get(position);
holder.story_image.setImageResource(model.getStory());
holder.profile_pic.setImageResource(model.getProfile());
holder.name.setText(model.getName());
holder.live_status.setImageResource(model.getStatus());
}
#Override
public int getItemCount() {
return list.size();
}
public class viewHolder extends RecyclerView.ViewHolder{
ImageView story_image,profile_pic,live_status;
TextView name;
public viewHolder(#NonNull View itemView) {
super(itemView);
story_image=itemView.findViewById(R.id.user_story_img_id);
profile_pic=itemView.findViewById(R.id.user_profile_pic_img_id);
live_status=itemView.findViewById(R.id.live_status_id);
name=itemView.findViewById(R.id.user_name_txt_id);
}
}
}
My database:
package com.assadcoorp.socialstar.DataTypes;
public class StoryDataType {
int status;
String name;
int story,profile;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getStory() {
return story;
}
public void setStory(int story) {
this.story = story;
}
public int getProfile() {
return profile;
}
public void setProfile(int profile) {
this.profile = profile;
}
public StoryDataType(int status, String name, int story, int profile) {
this.status = status;
this.name = name;
this.story = story;
this.profile = profile;
}
}
and home fragment:
package com.assadcoorp.socialstar;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.Toast;
import com.assadcoorp.socialstar.DataTypes.StoryDataType;
import com.assadcoorp.socialstar.Package.StoryAdapter;
import java.util.ArrayList;
public class HomeFragment extends Fragment {
RecyclerView story_rv;
ArrayList<StoryDataType> story_list;
public HomeFragment() {
// 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_home, container, false);
story_rv=view.findViewById(R.id.story_rv_id);
story_list = new ArrayList<>();
story_list.add(new StoryDataType(R.drawable.live,"Dragon",R.drawable.rain_drops_bg,R.drawable.profile_icon));
story_list.add(new StoryDataType(R.drawable.live,"Dragon",R.drawable.rain_drops_bg,R.drawable.profile_icon));
story_list.add(new StoryDataType(R.drawable.live,"Dragon",R.drawable.rain_drops_bg,R.drawable.profile_icon));
story_list.add(new StoryDataType(R.drawable.live,"Dragon",R.drawable.rain_drops_bg,R.drawable.profile_icon));
StoryAdapter adapter=new StoryAdapter(story_list,getContext());
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false);
story_rv.setLayoutManager(linearLayoutManager);
//story_rv.setNestedScrollingEnabled(true);
story_rv.setAdapter(adapter);
return view;
}
}
and sample recycler view:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/user_story_img_id"
android:layout_width="160dp"
android:layout_height="120dp"
android:scaleType="centerCrop"
android:src="#drawable/rain_drops_bg"
app:background="#color/light_red"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:riv_border_color="#333333"
app:riv_corner_radius="20dip"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_profile_pic_img_id"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="70dp"
android:padding="5dp"
android:src="#drawable/profile_icon"
app:layout_constraintBottom_toBottomOf="#+id/user_story_img_id"
app:layout_constraintEnd_toEndOf="#+id/user_story_img_id"
app:layout_constraintTop_toTopOf="#+id/user_story_img_id" />
<View
android:id="#+id/user_profile_pic_ring_id"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#drawable/circle_4"
app:layout_constraintBottom_toBottomOf="#+id/user_profile_pic_img_id"
app:layout_constraintEnd_toEndOf="#+id/user_profile_pic_img_id"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="#+id/user_profile_pic_img_id"
app:layout_constraintTop_toTopOf="#+id/user_profile_pic_img_id"
app:layout_constraintVertical_bias="1.0" />
<ImageView
android:id="#+id/live_status_id"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
app:layout_constraintStart_toStartOf="#+id/user_story_img_id"
app:layout_constraintTop_toTopOf="#+id/user_story_img_id"
app:srcCompat="#drawable/live" />
<TextView
android:id="#+id/user_name_txt_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="8dp"
android:background="#color/light_black_shade"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="#+id/user_story_img_id"
app:layout_constraintStart_toStartOf="#+id/user_story_img_id" />
</androidx.constraintlayout.widget.ConstraintLayout>
try to initialize your Arraylist in the HomeFragment class like this ArrayList story_list=new ArrayList();
and if you are using firebase to get the data create a empty constructor in the StoryDataType class;
My problem 1:I'm using android studio to build a recycler view.However,when I run the code,this notification pop up.
My problem 2:In MainActivity.java ,an error that shown cannot find system variable Recyclerview in line 23 pop up.May I know how to solve it?becuz I declared it already.
Below are my codes:
(MainActivity.java:)
package com.example.recyclerviewdemo;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
List <Details> detailsList;
MyAdapter myAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.recyclerView);
detailsList=new ArrayList<>();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
//passing data to model class
for (int i=0;i<=10;i++){
Details details=new Details("Java "+i,"This is description " +i);
detailsList.add(details);
}
myAdapter=new MyAdapter(detailsList);
recyclerView.setAdapter(myAdapter);
}
}
(activity_main.xml:)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
MyAdapter.java:
package com.example.recyclerviewdemo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.widget.TextViewOnReceiveContentListener;
import androidx.recyclerview.widget.RecyclerView;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
private List<Details> detailsList;
public MyAdapter(List<Details> detailsList) {
this.detailsList = detailsList;
}
#NonNull
#NotNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull #NotNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(
R.layout.rv_item_list,
parent,
false
);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull #NotNull MyAdapter.MyViewHolder holder, int
position) {
holder.tvTitle.setText(detailsList.get(position).getTitle());
holder.tvDesc.setText(detailsList.get(position).getTitle());
}
#Override
public int getItemCount() {
return detailsList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView tvTitle;
TextView tvDesc;
public MyViewHolder(#NonNull #org.jetbrains.annotations.NotNull View itemView) {
super(itemView);
tvTitle=itemView.findViewById(R.id.tvTitle);
tvDesc=itemView.findViewById(R.id.tvDescription);
}
}
}
Details.java:
package com.example.recyclerviewdemo;
public class Details {
private String title;
private String description;
public Details(String title, String description) {
this.title = title;
this.description = description;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
}
rv_item_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
android:layout_margin="5dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/a" />
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="200dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/tvTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
You forget to declare the id in the XML file..Add this in your activity xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
So here is my problem, I got an API that gives me the lastest news of many sources. Each one of them goes with a cardview. The problem here is, while I'm using the swipeRefresh, it gets duplicated cardViews with the same news, like if I have 10 news, it duplicates to 20 with the same ones.
Here is my code where I apply the swipeRefresh:
package com.example.newsapp4;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.example.newsapp4.Model.Articles;
import com.example.newsapp4.Model.Headlines;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class bbcnews extends AppCompatActivity {
Adapter adapter;
Intent intencion;
RecyclerView recyclerView;
public static String source = "My Source";
public static String API_KEY = "My API Key";
SwipeRefreshLayout srl;
List<Articles> articles = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bbcnews);
srl = findViewById(R.id.swipeRefresh);
srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
retrieveJson(source, API_KEY);
}
});
recyclerView = findViewById(R.id.recyclerView1);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new Adapter(bbcnews.this,articles);
recyclerView.setAdapter(adapter);
retrieveJson(source, API_KEY);
}
public void retrieveJson(String source, String apiKey){
srl.setRefreshing(true);
Call<Headlines> call = ApiClient.getInstance().getApi().getHeadlines(source, apiKey);
call.enqueue(new Callback<Headlines>() {
#Override
public void onResponse(Call<Headlines> call, Response<Headlines> response) {
if(response.isSuccessful() && response.body().getArticles() != null){
srl.setRefreshing(false);
articles.clear();
articles = response.body().getArticles();
adapter.setArticles(articles);
}
}
#Override
public void onFailure(Call<Headlines> call, Throwable t) {
srl.setRefreshing(false);
Toast.makeText(bbcnews.this, t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
});
}
public String getCountry(){
Locale locale = Locale.getDefault();
String country = locale.getCountry();
return country.toLowerCase();
}
public void aPerfil(View vista){
intencion = new Intent(this, profile_activity.class);
startActivity(intencion);
}
}
I don't think that I need to put the xml code with the progressbar and the swipeRefresh but here are both:
This one is the Items.xml where I created the cardView:
<?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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="4dp"
android:id="#+id/cardView"
app:cardCornerRadius="10dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/loader"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/image"
android:scaleType="centerCrop"
android:src="#drawable/img"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE"
android:textSize="20dp"
android:padding="10dp"
android:fontFamily="#font/g_bold"
android:textColor="#color/white"
android:id="#+id/tvTitle"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Source"
android:textSize="16dp"
android:padding="10dp"
android:ems="15"
android:fontFamily="#font/g_light"
android:textColor="#color/white"
android:id="#+id/tvSource"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/g_light"
android:gravity="right"
android:text="Date"
android:textColor="#color/white"
android:padding="10dp"
android:textSize="16dp"
android:id="#+id/tvDate"/>
</LinearLayout>
</FrameLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
And here the one with the swipeRefresh in the recyclerView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="#color/white"
tools:context=".bbcnews">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DINGO BBC NEWS"
android:textColor="#color/black"
android:textSize="20sp"
android:fontFamily="#font/g_bold"
android:background="#color/white"
android:padding="10dp"
android:textAlignment="center"/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:columnCount="2"
android:paddingLeft="20dp"
android:paddingRight="5dp"
android:background="#drawable/black_background"
android:rowCount="2">
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Search"
android:textColor="#color/grey"
android:textColorHint="#color/grey"
android:padding="5dp"
android:layout_column="0"
android:background="#drawable/black_background"
android:layout_row="0"
android:layout_columnWeight="1"
android:inputType="textPersonName" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:background="#drawable/black_background"
android:drawableRight="#drawable/ic_baseline_search_24"
android:layout_column="1"
android:layout_row="0"/>
</GridLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipeRefresh">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:id="#+id/recyclerView1"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
Also this is my adapter.java code:
package com.example.newsapp4;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import com.example.newsapp4.Model.Articles;
import com.squareup.picasso.Picasso;
import java.util.List;
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
Context context;
List<Articles> articles;
public Adapter(Context context, List<Articles> articles) {
this.context = context;
this.articles = articles;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
final Articles a = articles.get(position);
String imageUrl = a.getUrlToImage();
holder.tvTitle.setText(a.getTitle());
holder.tvSource.setText(a.getSource().getName());
holder.tvDate.setText(a.getPublishedAt());
Picasso.with(context).load(imageUrl).into(holder.imageView);
}
#Override
public int getItemCount() {
return articles.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView tvTitle,tvSource,tvDate;
ImageView imageView;
CardView cardView;
public ViewHolder(#NonNull View itemView) {
super(itemView);
tvTitle = itemView.findViewById(R.id.tvTitle);
tvSource = itemView.findViewById(R.id.tvSource);
tvDate = itemView.findViewById(R.id.tvDate);
imageView = itemView.findViewById(R.id.image);
cardView = itemView.findViewById(R.id.cardView);
}
}
public void setArticles(List<Articles> articles) {
this.articles.addAll(articles);
int count = getItemCount();
notifyItemRangeInserted(count, count + articles.size());
}
}
Thanks for your time!
// Clear adapter list before add to list.
public void setArticles(List<Articles> articles) {
if(this.articles!=null && this.articles.size()>0)
this.articles.clear();
this.articles.addAll(articles);
int count = getItemCount();
notifyItemRangeInserted(count, count + articles.size());
}
From what I can understand in your code is on the success of API call after Swipe Refresh which is this section here
articles.clear();
articles = response.body().getArticles();
adapter.setArticles(articles);
You are here clearing the article inside your activity, but the thing is inside your Adapter there is already another list of articles, you are not clearing them.
And then when you make the adapter.setArticles(articles); call, inside the following function, your articles get added to the already existing list of articles and thus, the duplicate list.
public void setArticles(List<Articles> articles) {
this.articles.addAll(articles);
int count = getItemCount();
notifyItemRangeInserted(count, count + articles.size());
}
To fix this you can make the following modifications to your function.
public void setArticles(List<Articles> articles, boolean clearAll) {
if(clearAll){ this.articles.clear(); }
this.articles.addAll(articles);
notifyDataSetChanged();
}
And then modify your function call as follows
adapter.setArticles(articles, true);
That way when the Boolean is true, it will clear the existing list. Also I would suggest you to replace the insert call with data set change call. Else you can make a separate function all together for adding elements and for clearing existing elements.
I have made an android application, and its getting successfully compiled without any errors. But when I run app in my android phone, then it does not show the desired output.
This is my MainActivity.java:
package wahab.com.timetabledemo;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.support.v7.widget.Toolbar;
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
private ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupUIViews();
initToolbar();
}
private void setupUIViews(){
toolbar = (Toolbar)findViewById(R.id.ToolbarMain);
listView = (ListView)findViewById(R.id.lvMain);
}
private void initToolbar(){
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("TimeTable App");
}
private void setupListView(){
String[] title = getResources().getStringArray(R.array.Main);
String[] description = getResources().getStringArray(R.array.Description);
SimpleAdaptor simpleAdaptor = new SimpleAdaptor(this, title, description);
listView.setAdapter(simpleAdaptor);
}
public class SimpleAdaptor extends BaseAdapter{
private Context mContext;
private LayoutInflater layoutInflater;
private TextView title, description;
private String[] titleArray;
private String[] descriptionArray;
private ImageView imageView;
public SimpleAdaptor(Context context, String[] title, String[] description){
mContext = context;
titleArray = title;
descriptionArray = description;
layoutInflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return titleArray.length;
}
#Override
public Object getItem(int i) {
return titleArray[i];
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
if(view == null){
view = layoutInflater.inflate(R.layout.main_activity_single_item,null);
}
title = (TextView)view.findViewById(R.id.tvMain);
description = (TextView)view.findViewById(R.id.tvDescription);
imageView = (ImageView)view.findViewById((R.id.ivMain));
title.setText(titleArray[i]);
description.setText(descriptionArray[i]);
if(titleArray[i].equalsIgnoreCase("Timetable")){
imageView.setImageResource(R.drawable.timetable);
}
else if(titleArray[i].equalsIgnoreCase("Subjects")){
imageView.setImageResource(R.drawable.book);
}
else if(titleArray[i].equalsIgnoreCase("Faculty")){
imageView.setImageResource(R.drawable.contact);
}
else{
imageView.setImageResource(R.drawable.settings);
}
return view;
}
}
}
The given above is a error free code.
This is my activity_main.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="wrap_content"
tools:context="wahab.com.timetabledemo.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/ToolbarMain"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimary"
app:titleTextColor="#color/white">
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lvMain"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:dividerHeight="10dp"
android:layout_below="#+id/ToolbarMain"
android:divider="#null">
</ListView>
</RelativeLayout>
In my activity_main.xml, I have used a RelativeLayout in which I have defined a Toolbar and a ListView. A ListView is defined so that I can add different list of operation.
This is my main_activity_single_item.xml:
<android.support.v7.widget.CardView android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:elevation="4dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="80dp"
android:layout_height="105dp"
android:id="#+id/ivMain"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvMain"
android:textStyle="bold"
android:text="Timetable"
android:layout_marginTop="6dp"
android:layout_marginLeft="6dp"
android:layout_toRightOf="#+id/ivMain"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvDescription"
android:text="description"
android:layout_marginLeft="6dp"
android:layout_marginTop="3dp"
android:layout_below="#+id/tvMain"
android:layout_toRightOf="#+id/ivMain"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvClick"
android:textSize="12sp"
android:text="click to know more"
android:layout_marginTop="6dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/tvDescription"
android:layout_alignBottom="#+id/ivMain"/>
</RelativeLayout>
In this above xml file, I have created a CardView which will consist of an ImageView and 3 TextView, which is placed using a RelativeLayout.
So, my code is getting compiled properly and my app is also running but am not getting the desired output.
You need to call setupListView() in onCreate to display the list
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupUIViews();
initToolbar();
setupListView(); // to display list
^^^^^^^^^^
}
guys in my project i need to click the item on the list and move to next activity using bundle i need to carry some data also, but i have some issue..
Please help me to move to next activity i can't understand what is the mistake i did,when i click on the item it is not even responding..
here i just use "e_name.setText("hiiii")" for testing purpose its not working.
AT THE END I HAVE MENTIONED MY LAYOUT CODES ALSO.
if possible please send me a link to learn more about custom adapter and list view..
//Main activity.java
package com.prematix.ashok.friday_9;
import android.app.ListActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
EditText e_name, e_desig, e_salary;
Button save;
String itemNames[];
String itemDescriptions[];
ListView itemsListView;
ArrayList<Item> list = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e_name = (EditText) findViewById(R.id.ed_name);
e_desig = (EditText) findViewById(R.id.ed_desig);
e_salary = (EditText) findViewById(R.id.ed_salary);
save = (Button) findViewById(R.id.save);
itemsListView = (ListView) findViewById(R.id.mylist);
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//create adapter object
CustomListAdapter adapter = new CustomListAdapter(getApplicationContext(), generateItemsList());
//set custom adapter as adapter to our list view
itemsListView.setAdapter(adapter);
}
private ArrayList<Item> generateItemsList() {
itemNames = new String[]{e_name.getText().toString()};
itemDescriptions = new String[]{e_desig.getText().toString()};
for (int i = 0; i < itemNames.length; i++) {
list.add(new Item(itemNames[i], itemDescriptions[i]));
}
return list;
}
});
itemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
e_name.setText("hiiiii");
}
});
// ListView itemsListView = (ListView)findViewById(R.id.list_view_items);
}
}
//CustommListAdapter.java
package com.prematix.ashok.friday_9;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by ${Nagaveni} on 2017-06-09.
*/
public class CustomListAdapter extends BaseAdapter {
private Context context;
private ArrayList<Item> items;
public CustomListAdapter(Context context,ArrayList<Item> items){
this.context = context;
this.items = items;
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int i) {
return items.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
if(view == null) {
view = LayoutInflater.from(context).inflate(R.layout.layout_list_view_row_items, viewGroup, false);
}
//get current item to be displayed
Item currentitem = (Item)getItem(i);
//get the text view for item name and item designation
TextView name = (TextView)view.findViewById(R.id.name);
TextView designation = (TextView)view.findViewById(R.id.desig);
TextView salary = (TextView)view.findViewById(R.id.salary);
//sets the text for item name and item designation from the current item object
name.setText(currentitem.getNames());
designation.setText(currentitem.getDesignation());
salary.setText("10,000");
//returns the view for current row
return view;
}
}
//here is my layout code
layout_list_view_items.xml
<?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="wrap_content">
<LinearLayout
android:layout_width="260dp"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name"
android:id="#+id/name"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="designation"
android:id="#+id/desig"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="salary"
android:id="#+id/salary"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="70dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.prematix.ashok.friday_9.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name"
android:ems="10"
android:id="#+id/ed_name" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Designation"
android:ems="10"
android:id="#+id/ed_desig" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Salary"
android:ems="10"
android:id="#+id/ed_salary" />
<Button
android:text="Save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/save" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mylist"/>
</LinearLayout>