This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I have a fragment with a foldingcell view
here is the mainfragment -
public class FriendFragmentMain extends Fragment {
private static final String TAG = FriendFragmentMain.class.getSimpleName();
private FriendsCellListAdapter friendsCellListAdapter;
private List<FriendsItem> friendsItems;
private String URL_FRIEND="http://212.224.76.127/friends/friends.json";
private FragmentActivity fragmentActivity;
private Activity mActivity;
private ListView friendsListView;
public static FriendFragmentMain newInstance(){
FriendFragmentMain friendFragmentMain = new FriendFragmentMain();
return friendFragmentMain;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.friend_fragment_main, container, false);
friendsListView = (ListView) getActivity().findViewById(R.id.friend_super_list);
friendsItems = new ArrayList<>();
friendsCellListAdapter = new FriendsCellListAdapter(mActivity, friendsItems);
friendsListView.setAdapter(friendsCellListAdapter);
friendsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
((FoldingCell) view).toggle(false);
friendsCellListAdapter.registerToggle(pos);
}
});
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Cache.Entry entry = cache.get(URL_FRIEND);
if (entry != null){
try {
String data = new String(entry.data, "UTF-8");
try {
parseJsonFriend(new JSONObject(data));
} catch (JSONException e){
e.printStackTrace();
}
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
} else {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
URL_FRIEND, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response:" + response.toString());
if (response != null) {
parseJsonFriend(response);
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "ERROR:" + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
}
return view;
}
private void parseJsonFriend(JSONObject response){
try {
JSONArray friendArray = response.getJSONArray("friends");
for (int i =0; i < friendArray.length(); i++){
JSONObject friendObj = (JSONObject) friendArray.get(i);
FriendsItem item = new FriendsItem();
item.setId(friendObj.getInt("id"));
item.setName(friendObj.getString("name"));
item.setProfilePic(friendObj.getString("profilePic"));
item.setBackgroundImage(friendObj.getString("backgroundImage"));
item.setStatus(friendObj.getString("status"));
item.setWork(friendObj.getString("work"));
item.setLocation(friendObj.getString("location"));
String friendUrl = friendObj.isNull("website")? null : friendObj
.getString("website");
item.setWebsite(friendUrl);
friendsItems.add(item);
}
friendsCellListAdapter.notifyDataSetChanged();
} catch (JSONException e){
e.printStackTrace();
}
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = activity;
}
}
the base adapter looks like this -
public class FriendsCellListAdapter extends BaseAdapter{
private HashSet<Integer> unfoldedIndexes = new HashSet<>();
private View.OnClickListener defaultMessageButton;
private View.OnClickListener defaultViewProfileButton;
private Activity activity;
private Context context;
private LayoutInflater inflater;
private List<FriendsItem> friendsItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public FriendsCellListAdapter(Activity activity, List<FriendsItem> friendsItems){
this.activity = activity;
this.friendsItems = friendsItems;
}
#Override
public int getCount() {
return friendsItems.size();
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public Object getItem(int position) {
return friendsItems.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
if (inflater==null)
inflater = (LayoutInflater)activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FriendsItem item = friendsItems.get(position);
FoldingCell cell = (FoldingCell) convertView;
ViewHolder viewHoler;
if (cell == null){
viewHoler = new ViewHolder();
cell = (FoldingCell) inflater.inflate(R.layout.friends_cell, parent, false);
viewHoler.profilePic = (NetworkImageView) cell.findViewById(R.id.friends_profile_pic);
viewHoler.clientName = (LoginTextView) cell.findViewById(R.id.client_name);
viewHoler.friendStatus = (LoginTextView) cell.findViewById(R.id.friend_status);
viewHoler.backgroundImage = (NetworkImageView) cell.findViewById(R.id.friend_background_image);
viewHoler.friendAvatar = (NetworkImageView) cell.findViewById(R.id.friends_avatar);
viewHoler.friendName = (LoginTextView) cell.findViewById(R.id.friend_name);
viewHoler.friendLocation = (LoginTextView) cell.findViewById(R.id.friend_location);
viewHoler.friendURL = (LoginTextView) cell.findViewById(R.id.friend_url);
viewHoler.friendWork = (LoginTextView) cell.findViewById(R.id.friend_work);
cell.setTag(viewHoler);
} else {
if (unfoldedIndexes.contains(position)){
cell.unfold(true);
} else {
cell.fold(true);
}
viewHoler = (ViewHolder) cell.getTag();
}
viewHoler.clientName.setText(item.getName());
viewHoler.friendName.setText(item.getName());
//chech for empty status
if (!TextUtils.isEmpty(item.getStatus())){
viewHoler.friendStatus.setText(item.getStatus());
viewHoler.friendStatus.setVisibility(View.VISIBLE);
} else {
viewHoler.friendStatus.setVisibility(View.GONE);
}
//check for empty location
if (!TextUtils.isEmpty(item.getLocation())){
viewHoler.friendLocation.setText(item.getLocation());
viewHoler.friendLocation.setVisibility(View.VISIBLE);
} else {
viewHoler.friendLocation.setVisibility(View.GONE);
}
//check for null url
if (item.getWebsite() != null){
viewHoler.friendURL.setText(Html.fromHtml("" + item.getWebsite()+""));
viewHoler.friendURL.setMovementMethod(LinkMovementMethod.getInstance());
viewHoler.friendURL.setVisibility(View.VISIBLE);
} else {
viewHoler.friendURL.setVisibility(View.GONE);
}
//check for empty work
if (!TextUtils.isEmpty(item.getWork())){
viewHoler.friendWork.setText(item.getWork());
viewHoler.friendWork.setVisibility(View.VISIBLE);
}else {
viewHoler.friendWork.setVisibility(View.GONE);
}
//profile pic
viewHoler.profilePic.setImageUrl(item.getProfilePic(), imageLoader);
viewHoler.friendAvatar.setImageUrl(item.getProfilePic(), imageLoader);
//background image
viewHoler.backgroundImage.setImageUrl(item.getBackgroundImage(), imageLoader);
return convertView;
}
public void registerToggle(int position){
if (unfoldedIndexes.contains(position))
registerFold(position);
else
registerUnfold(position);
}
public void registerFold(int position){unfoldedIndexes.remove(position);}
public void registerUnfold(int position){
unfoldedIndexes.add(position);
}
private class ViewHolder{
NetworkImageView profilePic;
LoginTextView clientName;
LoginTextView friendStatus;
NetworkImageView backgroundImage;
NetworkImageView friendAvatar;
LoginTextView friendName;
LoginTextView friendLocation;
LoginTextView friendURL;
LoginTextView friendWork;
}
}
now when i run it it throws -
Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at com.evolustudios.askin.askin.src.fragments.FriendFragmentMain.onCreateView(FriendFragmentMain.java:60)
this error. i am unable to find out why its throwing a null object? can anyone throw a light on why its showing null object.
the views are here- friends_cell
<com.ramotion.foldingcell.FoldingCell xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
xmlns:folding-cell="http://schemas.android.com/apk/res-auto"
folding-cell:additionalFlipsCount="2"
folding-cell:animationDuration="1300"
folding-cell:backSideColor="#color/bgBackSideColor">
<include layout="#layout/friends_content_layout"/>
<include layout="#layout/friends_cell_title_layout"/>
</com.ramotion.foldingcell.FoldingCell>
friends_cell_title_layout -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<!--LEFT Part -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:background="#color/feed_item_border">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/friends_profile_pic"
android:scaleType="fitCenter"/>
</RelativeLayout>
<!--RIGHT Part-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingBottom="20dp"
android:paddingEnd="20dp"
android:paddingStart="15dp"
android:paddingTop="20dp"
android:background="#color/feed_item_border">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:id="#+id/title_from_to_dots"
android:layout_marginEnd="10dp"
android:src="#drawable/from_to_purple"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/client_name"
android:layout_alignTop="#+id/title_from_to_dots"
android:layout_marginTop="-5dp"
android:layout_toEndOf="#+id/title_from_to_dots"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="#android:color/holo_blue_dark"
android:textSize="16sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/friend_profile_divider"
android:layout_below="#+id/client_name"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="#+id/title_from_to_dots"
android:src="#color/contentDividerLine"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_status"
android:layout_below="#+id/friend_profile_divider"
android:layout_toEndOf="#+id/title_from_to_dots"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="#android:color/holo_blue_dark"
android:textSize="16sp"/>
</RelativeLayout>
and friend_content_layout -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<!--Content header line-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/text_password"
android:paddingBottom="7dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="7dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/menu_icon"/>
</RelativeLayout>
<!--Content header Image-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/friend_background_image"
android:scaleType="centerCrop"/>
</RelativeLayout>
<!--Content body layout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="6dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="9dp">
<!--avatar and name-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friends_avatar"
android:layout_alignParentStart="true"
android:layout_marginBottom="5dp"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_name"
android:layout_alignTop="#+id/friends_avatar"
android:layout_marginBottom="2dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/friends_avatar"
android:textColor="#color/mainTextColor"
android:textSize="18sp"
android:textStyle="bold"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_location"
android:layout_alignStart="#+id/friend_name"
android:layout_marginBottom="-2dp"
android:layout_marginStart="3dp"
android:layout_below="#+id/friend_name"
android:textColor="#a9a9a9"
android:textSize="12sp"/>
</RelativeLayout>
<!--Divider Line-->
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="6dp"
android:layout_marginTop="9dp"
android:src="#color/contentDividerLine"/>
<!--Address Part-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/url_badge"
android:textColor="#a9a9a9"
android:layout_alignParentStart="true"
android:text="WEBSITE"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_url"
android:layout_alignStart="#+id/url_badge"
android:layout_below="#+id/url_badge"
android:textColor="#color/mainTextColor"
android:textSize="18sp"
android:textStyle="bold"/>
</RelativeLayout>
</LinearLayout>
<!--Divider Line-->
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="6dp"
android:layout_marginTop="7dp"
android:src="#color/contentDividerLine"/>
<!--Work Part-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/work_badge"
android:textColor="#a9a9a9"
android:layout_alignParentStart="true"
android:text="WORK"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_work"
android:layout_alignStart="#+id/work_badge"
android:layout_below="#+id/work_badge"
android:textColor="#color/mainTextColor"
android:textSize="18sp"
android:textStyle="bold"/>
</RelativeLayout>
</LinearLayout>
<!--Buttons-->
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/friend_send_message"
android:layout_marginTop="16dp"
android:background="#color/btnRequest"
android:padding="10dp"
android:text="Send Message"
android:textAlignment="center"
android:textColor="#color/mainTextColor"
android:textSize="20sp"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/friend_view_profile"
android:layout_marginTop="16dp"
android:background="#color/btnRequest"
android:padding="10dp"
android:text="View Profile"
android:textAlignment="center"
android:textColor="#color/mainTextColor"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
Initialize friendsItems before passing it to friendsCellListAdapter
friendsItems = new ArrayList<FriendsItem>(); // add this line
friendsCellListAdapter = new FriendsCellListAdapter(mActivity, friendsItems);
friendsListView.setAdapter(friendsCellListAdapter);
Related
I am facing very strange problem. I am using recycler view and passing an ArrayList of data. that list has data I have checked and Adapter is calling "getItemCount()" method but not calling "onCreateViewHolder/onBindViewHolder method. Below is the code I am using
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:id="#+id/ll_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ContactsListActivity">
<TextView
android:id="#+id/tv_network_notifier_view"
android:layout_width="match_parent"
android:layout_height="#dimen/network_notifier_width"
android:background="#android:color/black"
android:gravity="center"
android:textColor="#android:color/white"
android:visibility="gone" />
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="#dimen/tool_bar_height"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/backButton"
android:layout_width="#dimen/action_icon"
android:layout_height="#dimen/action_icon"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="?selectableItemBackgroundBorderless"
android:padding="10dp"
android:src="#drawable/back_ico" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:text="Contacts"
android:textColor="#color/white"
android:textSize="#dimen/text_heading_title" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<androidx.appcompat.widget.SearchView
android:id="#+id/contactSearchView"
android:layout_width="match_parent"
android:layout_height="#dimen/button_height_dialog"
android:layout_marginLeft="23dp"
android:layout_marginTop="10dp"
android:layout_marginRight="23dp"
android:layout_marginBottom="10dp"
android:background="#drawable/button_fill_white"
app:iconifiedByDefault="false" />
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/contactsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/ll_contact_number"
android:layout_marginTop="5dp" />
<LinearLayout
android:id="#+id/nofriendAvailable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="#dimen/logo_size"
android:layout_height="#dimen/logo_size"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:src="#drawable/ic_gray_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="#dimen/edittext_height"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="No Friends Available"
android:textAllCaps="false"
android:textColor="#color/colorGray"
android:textSize="#dimen/text_very_small" />
</LinearLayout>
<RelativeLayout
android:id="#+id/ll_contact_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_dialer_pad"
android:background="#color/white"
android:orientation="horizontal">
<EditText
android:id="#+id/et_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/text_main"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:gravity="fill_vertical|center"
android:maxLines="1"
android:scrollHorizontally="true"
android:textColor="#android:color/black"
android:textSize="#dimen/phone_number_text_size"
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="#+id/img_delete_number"
android:layout_width="#dimen/delete_number_width"
android:layout_height="#dimen/delete_number_height"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_right_for_dialer_number_delete"
android:layout_marginBottom="#dimen/margin_bottom_for_dialer_number_delete"
android:onClick="onClick"
android:padding="#dimen/padding_delete_number"
android:src="#drawable/back_dial_ico"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_dialer_pad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_bottom_dialer_view"
android:background="#color/white"
android:paddingLeft="#dimen/dialer_button_margin_left"
android:paddingRight="#dimen/dialer_button_margin_right"
android:visibility="gone">
<LinearLayout
android:id="#+id/Row1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="5">
<!-- Buttons 1 2 3 -->
<ImageButton
android:id="#+id/Button1"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num1" />
<ImageButton
android:id="#+id/Button2"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num2" />
<ImageButton
android:id="#+id/Button3"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num3" />
</LinearLayout>
<!-- Buttons 4 5 6 -->
<LinearLayout
android:id="#+id/Row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Row1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:weightSum="5">
<ImageButton
android:id="#+id/Button4"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num4" />
<ImageButton
android:id="#+id/Button5"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num5" />
<ImageButton
android:id="#+id/Button6"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num6" />
</LinearLayout>
<!-- Buttons 7 8 9 -->
<LinearLayout
android:id="#+id/Row3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Row2"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:weightSum="5">
<ImageButton
android:id="#+id/Button7"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num7" />
<ImageButton
android:id="#+id/Button8"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num8" />
<ImageButton
android:id="#+id/Button9"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num9" />
</LinearLayout>
<!-- Buttons * 0 # -->
<LinearLayout
android:id="#+id/Row4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Row3"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:weightSum="5">
<ImageButton
android:id="#+id/ButtonStar"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num0l" />
<ImageButton
android:id="#+id/Button0"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num0" />
<ImageButton
android:id="#+id/ButtonHash"
style="#style/DialerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:src="#drawable/num0r" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_bottom_dialer_view"
android:layout_width="match_parent"
android:layout_height="#dimen/dialer_button_height"
android:layout_alignParentBottom="true"
android:background="#color/white">
<ImageView
android:id="#+id/iv_dialer_opener"
android:layout_width="#dimen/dialer_button_width"
android:layout_height="#dimen/dialer_button_height"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/dialer_opener"
android:tag="dialer" />
<ImageView
android:id="#+id/iv_dialer_closer"
android:layout_width="#dimen/dialer_button_width"
android:layout_height="#dimen/dialer_button_height"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="#drawable/dial_ico"
android:tag="dialer"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Below is the Adater
public class ContactCallAdapter extends RecyclerView.Adapter<ContactCallAdapter.ViewHolder> {
private static final String TAG = ContactCallAdapter.class.getSimpleName();
private List<ContactModel> contactsList;
private List<ContactModel> contactsListCopy = new ArrayList<>();
private Context context;
private OnContactClickListener onContactClickListener;
private OnCallClickListener onCallClickListener;
private boolean isCall = false;
boolean isPending = false;
private int callType = 0;
private OnInviteCLickListener onInviteCLickListener;
private OnCancelClickListener onCancelClickListener;
public interface OnInviteCLickListener {
void onitemClick(String fromWhere, String customerLoginID);
}
public interface OnCancelClickListener {
void onClick(ContactModel contactModel);
}
public ContactCallAdapter(OnInviteCLickListener listener, int callType, List<ContactModel> contactsList, OnContactClickListener onContactClickListener,
OnCallClickListener onCallClickListener) {
LogUtility.logInfo(TAG, "Constructor is called");
this.contactsList = contactsList;
contactsListCopy.addAll(contactsList);
this.onContactClickListener = onContactClickListener;
this.onCallClickListener = onCallClickListener;
this.callType = callType;
this.onInviteCLickListener = listener;
if (callType != 0) isCall = true;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LogUtility.logInfo(TAG, "onCreateViewHolder is called");
context = parent.getContext();
Activity activity = (Activity) context;
FontsUtility.applyCustomFont(activity);
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_contact_for_call, parent, false));
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, final int position) {
LogUtility.logInfo(TAG, "onBindViewHolder is called");
holder.bind(position, onContactClickListener, onCallClickListener);
}
#Override
public int getItemCount() {
LogUtility.logInfo(TAG, "getItemCount and count is " + contactsList.size() + " hashcode is " + contactsList.hashCode());
return contactsList.size();
}
And below is Activity Code
public class ContactsListActivity extends BaseActivity implements ContactCallAdapter.OnInviteCLickListener, OnContactClickListener {
private final String TAG = ContactsListActivity.class.getSimpleName();
private static final byte ZER0 = 0;
private TextView tvNetworkStatusNotifier;
private boolean shouldShowDialer;
public static synchronized ContactsListActivity getInstance() {
return mInstance;
}
static ContactsListActivity mInstance = null;
private RecyclerView recyclerView;
private androidx.appcompat.widget.SearchView contactSearchView;
private ImageButton imgBtn0, imgBtn1, imgBtn2, imgBtn3, imgBtn4, imgBtn5, imgBtn6, imgBtn7, imgBtn8, imgBtn9, imgBtnAsteric, imgBtnHash;
private ImageView imgDeleteNumber, backButton, ivDialerPadOpener, ivDialerCloser;
private RelativeLayout rlDialerPad;
private EditText etPhoneNumber;
private RelativeLayout rlContactNumber, rlBottomViewDialer;
ContactCallAdapter adapter;
Context context;
AppSharedPref pref;
Dialog progressDialog;
protected IHubProxy hub = null;
ArrayList<ContactModel> arrayListContact;
ArrayList<RequestModel> arrayListRequest;
ArrayList<RequestModel> arrayListRequestCount;
ArrayList<RequestModel> arrayListRequestOtherContact;
int callType = 0;
ArrayList<ContactModel> arrayPendingListContact;
TextView tvNotificationcount;
Integer whichOneUpdate = null;
SwipeRefreshLayout swipeLayout;
Dialog dialog;
boolean update = false;
LinearLayout nofriendAvailable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts_list);
FontsUtility.applyCustomFont(this);
context = this;
mInstance = this;
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
pref = AppSharedPref.getInstance();
progressDialog = Utils.progressDialog(context);
recyclerView = findViewById(R.id.contactsList);
nofriendAvailable = findViewById(R.id.nofriendAvailable);
imgDeleteNumber = findViewById(R.id.img_delete_number);
ivDialerPadOpener = findViewById(R.id.iv_dialer_opener);
ivDialerCloser = findViewById(R.id.iv_dialer_closer);
rlDialerPad = findViewById(R.id.rl_dialer_pad);
rlBottomViewDialer = findViewById(R.id.rl_bottom_dialer_view);
etPhoneNumber = findViewById(R.id.et_phone_number);
tvNetworkStatusNotifier = findViewById(R.id.tv_network_notifier_view);
tvNotificationcount = findViewById(R.id.tvNotificationcount);
contactSearchView = findViewById(R.id.contactSearchView);
rlContactNumber = findViewById(R.id.ll_contact_number);
contactSearchView.setQueryHint("Search");
EditText searchEditText =
searchEditText.setHintTextColor(getResources().getColor(R.color.colorGray));
ImageView icon = contactSearchView.findViewById(R.id.search_button);
icon.setImageResource(R.drawable.search_gray_ico_la);
icon.setColorFilter(Color.BLACK);
ImageView iconClose =
contactSearchView.findViewById(R.id.search_close_btn);
iconClose.setColorFilter(getResources().getColor(R.color.black2));
iconClose.setImageResource(R.drawable.close_gray_ico_la);
arrayListContact = new ArrayList<>();
arrayListRequest = new ArrayList<>();
arrayListRequestCount = new ArrayList<>();
arrayPendingListContact = new ArrayList<>();
arrayListRequestOtherContact = new ArrayList<>();
whichOneUpdate = 1;
contactSearchView.setVisibility(View.VISIBLE);
Intent intent = getIntent();
if (intent.hasExtra(Constants.PARAM_TYPE)) {
callType = intent.getIntExtra(Constants.PARAM_TYPE, 0);
//from call
}
if (intent.hasExtra(Constants.PARAM_SHOULD_SHOW_DIALER)) {
shouldShowDialer = intent.getBooleanExtra(Constants.PARAM_SHOULD_SHOW_DIALER, false);
if (shouldShowDialer)
rlBottomViewDialer.setVisibility(View.VISIBLE);
else
rlBottomViewDialer.setVisibility(View.GONE);
}
swipeLayout.setOnRefreshListener(() -> {
contactSearchView.setQuery("", false);
swipeLayout.setRefreshing(true);
//getContacts(true);
getAllContactsAgain();
swipeLayout.setRefreshing(false);
});
contactSearchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String newText) {
if (adapter != null)
adapter.filter(newText);
return true;
}
#Override
public boolean onQueryTextChange(String newText) {
if (adapter != null)
adapter.filter(newText);
return true;
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setItemAnimator(new DefaultItemAnimator());
getAllContactsAgain();
}
}
public void getAllContactsAgain() {
arrayListContact.clear();
arrayListRequestOtherContact.clear();
arrayPendingListContact.clear();
if (Utils.checkPermissionContact(context))
if (shouldShowDialer)
arrayListContact = getContactsList();
getContacts(false);
}
void getContacts(final boolean addtoRecyler) {
if (HubUtility.reconnectHubIfRequired(this, TAG))
return;
showDialog();
ArrayList<String> settingsList = new ArrayList<>();
settingsList.add("" + pref.getUserId());
hub = CallReceivingService.hub;
hub.Invoke(Constants.HUB_CONTACTS, settingsList,
new HubInvokeCallback() {
#Override
public void OnResult(boolean status, String response) {
dismissDialog();
swipeLayout.setRefreshing(false);
try {
ContactPojo contactPojo = new
Gson().fromJson(response, ContactPojo.class);
if (contactPojo != null) {
if (contactPojo.isStatus()) {
arrayPendingListContact.clear();
//arrayListContact.clear();
arrayPendingListContact.addAll(contactPojo.getUserList());
for (int a = 0; a <
arrayPendingListContact.size(); a++) {
if
(arrayPendingListContact.get(a).getCustomerContactType() ==
Constants.ACCEPTED
||
arrayPendingListContact.get(a).getCustomerContactType() ==
Constants.ACCEPTED_BY) {
arrayListContact.add(0,
contactPojo.getUserList().get(a));
}
}
Utils.e("Hub Size", "" +
arrayListContact.size());
adapter = new
ContactCallAdapter(ContactsListActivity.this::onitemClick, callType,
arrayListContact,
ContactsListActivity.this,
contactModel -> {
//allowed call on behalf of
statuses
if (contactModel.isPhone()) {
Intent inte = getIntent();
inte.putExtra(Constants.PARAM_SIP_CALL, contactModel.getNumber());
inte.putExtra(Constants.PARAM_SIP_CALLER_NAME, contactModel.getName());
setResult(RESULT_OK, inte);
finish();
} else {
if
(contactModel.getCustomerCommunicationStatus() == Constants.ONLINE &&
(contactModel.getCustomerContactType() == Constants.ACCEPTED ||
contactModel.getCustomerContactType() == Constants.ACCEPTED_BY)) {
Intent inte =
getIntent();
inte.putExtra(Constants.PARAM_CONTACT, contactModel);
setResult(RESULT_OK,
inte);
finish();
} else {
Utils.showMessage("User
is not available.");
}
}
});
recyclerView.setAdapter(adapter);
recyclerView.requestFocus();
}
}
isEmpty();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void OnError(Exception e) {
}
});
}
Any help would be highly appreciated. Although this question has already been asked. I have checked those. Those are not valid in my case like
Returning zero from getIemCount method
Not passing layout manager
As per the official documentation of the Swipe refresh layout
"This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child."
So consider re-structuring your layout so that the RecyclerView is the only child under Swipe refresh layout.
I have a grid view and data updated in grid view using api calls and grid item loads a image from url using picasso library all are perfect but when i am scrolling down to up the grid items not scrolled and repeating the items(up to down scrolling was perfect).
Adapterclass.java
private class ProductAdapter extends BaseAdapter {
ViewHolder holder = null;
#Override
public int getCount() {
return mProducts != null ? mProducts.size() : 0;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
holder = new ViewHolder();
if (convertView == null) {
// convertView = LayoutInflater.from(Products_activity.this).inflate(R.layout.product_layout, null, false);
LayoutInflater vi = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.product_layout, null);
holder.product_name = (TextView) convertView.findViewById(R.id.product_name);
holder.product_descr = (TextView) convertView.findViewById(R.id.product_desc);
holder.product_price = (TextView) convertView.findViewById(R.id.product_price);
holder.product_pic = (ImageView) convertView.findViewById(R.id.iv_division_img);
holder.product_share = (ImageView) convertView.findViewById(R.id.productshare_button);
holder.like_image=(ImageView) convertView.findViewById(R.id.like_image);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
if (mProducts != null) {
String url = "http://staggershop.pivalue.net/assets/product_images/"+mProducts.get(position).product_image;
String urls = url.replaceAll(" ", "%20");
Picasso.with(getApplicationContext()).load(urls).resize(300,300).noFade().error(R.drawable.home_brands).into(holder.product_pic);
holder.product_name.setText(mProducts.get(position).product_name);
//product_descr.setText(mProducts.get(position).pr);
// product_price.setText(mProducts.get(position).product_price);
/* Picasso
.with(getApplicationContext())
.setLoggingEnabled(true);
Picasso.with(getApplicationContext())
.load(urls)
.error(R.drawable.home_brands).memoryPolicy(MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_STORE)
.into(product_pic);*/
holder.product_descr.setText(mProducts.get(position).product_description);
if(!recently_beans.isEmpty()){
for(int i=0;i<recently_beans.size();i++) {
if (mProducts.get(position).prdid.equals(recently_beans.get(i).prod_id))
{
holder.like_image.setImageResource(R.drawable.like);
}
}
notifyDataSetChanged();
}
}
holder.product_share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
}
});
holder.like_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
if (!recently_beans.isEmpty()) {
for (int i = 0; i < recently_beans.size(); i++) {
if (mProducts.get(position).prdid.equals(recently_beans.get(i).prod_id)) {
holder.like_image.setImageResource(R.drawable.dislike);
Inserfavorite(mProducts.get(position).prdid);
}
}
}
}
});
}
});
// notifyDataSetChanged();
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Inserrecent(mProducts.get(position).prdid);
Intent intent = new Intent(Products_activity.this, Product_description.class);
startActivity(intent);
}
});
return convertView;
}
}
public static class ViewHolder {
public TextView product_name;
public TextView product_descr;
public TextView product_price;
public ImageView product_pic ;
public ImageView product_share;
public ImageView like_image;
}
This my product.xml
<RelativeLayout
android:id="#+id/rl_divisioin_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/product_img">
<ImageView
android:id="#+id/iv_division_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="#drawable/home_brands" />
</LinearLayout>
<LinearLayout
android:id="#+id/prod_name_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/product_img"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="4dp"
android:fontFamily="#string/font_family_regular"
android:gravity="center"
android:padding="5dp"
android:maxLines="1"
android:text="product name"
android:textColor="#color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/product_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="4dp"
android:fontFamily="#string/font_family_regular"
android:gravity="center"
android:maxLines="1"
android:padding="5dp"
android:text="product Description"
android:textColor="#color/black"
android:textSize="10sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/product_desc"
android:layout_gravity="center"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/product_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:elevation="4dp"
android:text="100$"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/productshare_button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:elevation="4dp"
android:layout_marginRight="5dp"
android:src="#mipmap/symbol_dotss"
android:text="product name"
android:textColor="#color/black"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="5dp"
android:id="#+id/like_image"
android:layout_alignParentEnd="true"
android:src="#drawable/dislike" />
</RelativeLayout>
activty_product.xml
<android.support.design.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"
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rltool"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar1"
android:background="#color/textColorPrimary"
app:titleTextColor="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/AppTheme.Toolbar"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/search1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/background_shape_buttons">
<!-- <EditText
android:id="#+id/searchEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#D6D5C0"
android:hint="Search..................."
android:layout_gravity="center"
android:backgroundTint="#00000000" />-->
<SearchView
android:id="#+id/search"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textColorHint="#D6D5C0"
android:text="#string/search"
android:layout_gravity="center"
android:iconifiedByDefault="false">
<requestFocus />
</SearchView>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<View
android:id="#+id/shadow_view"
android:layout_width="match_parent"
android:layout_alignBottom="#+id/toolbar1"
android:visibility="visible"
android:layout_height="3dp"
android:background="#drawable/toolbar_shadow" />
</RelativeLayout>
<GridView
android:id="#+id/product_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scrollbars="vertical"
android:layout_margin="15dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:verticalSpacing="10dp">
</GridView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
To avoid the unexpected behaviour , provide the implementations of
#Override
public Object getItem(int position) {
return mProducts.get(position);
}
#Override
public long getItemId(int position) {
//return position; or better to provide some unique id
// as there is one in your code, product id
return mProducts.get(position).prod_id;
}
Note : remove notifyDataSetChanged(); in getView because it will trigger the adapter to refresh all view while they are under creating which can cause this behaviour.
Recommended Read
What is the intent of the methods getItem and getItemId in the Android class BaseAdapter?
i have two adapters and a fragment, and i want to display feeds on two views, one bottom and one recycler view. Although the Json was working with a list adapter. its not working with the recycler view.
here is the main fragment
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardExpand;
import it.gmariotti.cardslib.library.internal.CardHeader;
import it.gmariotti.cardslib.library.view.CardViewNative;
import jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout;
public class FeedFragmentAlternative extends Fragment{
private static final String TAG = FeedFragmentAlternative.class.getSimpleName();
private String URL_FEED = "http://api.androidhive.info/feed/feed.json";
private WaveSwipeRefreshLayout mWaveSwipeRefresh;
int duration = 200;
private List<FeedItem> FeedItems;
public static FeedFragmentAlternative newInstance(){
FeedFragmentAlternative feedFragmentAlternative = new FeedFragmentAlternative();
return feedFragmentAlternative;
}
private void refresh(){
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mWaveSwipeRefresh.setRefreshing(false);
}
},3000);
}
private ExpandablePager pager;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.feed_activity_alternate, container, false);
final List<FeedItem> myFeedList = new ArrayList<>();
final FeedExpandableAdapter adapter = new FeedExpandableAdapter(myFeedList);
pager = (ExpandablePager) getActivity().findViewById(R.id.bottom_feed_container);
pager.setAdapter(adapter);
pager.setOnSliderStateChangeListener(new OnSliderStateChangeListener() {
#Override
public void onStateChanged(View page, int index, int state) {
toggleContent(page, state, duration);
}
#Override
public void onPageChanged(View page, int index, int state) {
toggleContent(page, state, 0);
}
});
final RecyclerView mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feeds_list_recycler_view);
mRecyclerView.setHasFixedSize(true);
final FeedGridAdapter a = new FeedGridAdapter(myFeedList);
a.setListener(new OnItemClickedListener() {
#Override
public void onItemClicked(int index) {
pager.setCurrentItem(index, false);
pager.animateToState(ExpandablePager.STATE_EXPANDED);
}
});
mWaveSwipeRefresh = (WaveSwipeRefreshLayout)view.findViewById(R.id.feed_wave_swipe_layout_refresh_alternate);
mWaveSwipeRefresh.setColorSchemeColors(Color.WHITE, Color.GREEN);
mWaveSwipeRefresh.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
pager.setAdapter(adapter);
mRecyclerView.setAdapter(a);
FeedFragmentAlternative.newInstance();
refresh();
}
});
mWaveSwipeRefresh.setWaveColor(Color.parseColor("#80C5EFF7"));
mWaveSwipeRefresh.setMaxDropHeight((int)(mWaveSwipeRefresh.getHeight() * 0.9));
mRecyclerView.setAdapter(a);
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Cache.Entry entry = cache.get(URL_FEED);
if (entry != null){
try {
String data = new String (entry.data, "UTF-8");
try {
parseJsonFeed(new JSONObject(data));
} catch (JSONException e){
e.printStackTrace();
}
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
} else {
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET,
URL_FEED, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response:" + response.toString());
if (response != null){
parseJsonFeed(response);
}
}
},new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "ERROR:" + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jsonReq);
}
return view;
}
private void toggleContent(final View page, final int state, int duration){
final int headerHeight = (int) getResources().getDimension(R.dimen.header_height);
if (page != null){
ValueAnimator animator = state == ExpandablePager.STATE_EXPANDED ? ValueAnimator.ofFloat(1,0): ValueAnimator.ofFloat(0,1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
page.findViewById(R.id.profile_name_header).setTranslationY(25 * (1 - ((Float) animation.getAnimatedValue())));
page.findViewById(R.id.profile_name_header).setTranslationX(-headerHeight * (1 - ((Float)animation.getAnimatedValue())));
page.findViewById(R.id.feed_time_stamp_header).setAlpha(((Float)animation.getAnimatedValue()));
page.findViewById(R.id.profile_pic_header_image).setAlpha(((Float)animation.getAnimatedValue()));
page.findViewById(R.id.feed_like_bottom_sheet).setAlpha(((Float) animation.getAnimatedValue()));
}
});
animator.setDuration((long)(duration * 5));
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
}
private void parseJsonFeed(JSONObject response){
try {
JSONArray feedArray = response.getJSONArray("feed");
for (int i = 0;i < feedArray.length(); i++){
JSONObject feedObj = (JSONObject) feedArray.get(i);
FeedItem item = new FeedItem();
item.setId(feedObj.getInt("id"));
item.setName(feedObj.getString("name"));
String image = feedObj.isNull("image")? null : feedObj
.getString("image");
item.setImge(image);
item.setStatus(feedObj.getString("status"));
item.setProfilePic(feedObj.getString("profilePic"));
item.setTimeStamp(feedObj.getString("timeStamp"));
String feedUrl = feedObj.isNull("url")? null : feedObj
.getString("url");
item.setUrl(feedUrl);
FeedItems.add(item);
}
} catch (JSONException e){
e.printStackTrace();
}
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initCards();
}
private void initCards(){
init_standard_header_with_expandcollapse_button();
}
private void init_standard_header_with_expandcollapse_button(){
Card card = new Card(getActivity());
CardHeader header = new CardHeader(getActivity());
header.setButtonExpandVisible(true);
card.addCardHeader(header);
CardExpand expand = new CardExpand(getActivity());
expand.setTitle("expanded");
CardViewNative cardViewNative = (CardViewNative) getActivity().findViewById(R.id.feed_card_style);
cardViewNative.setCard(card);
}
}
the grid adapter is as follows
public class FeedGridAdapter extends RecyclerView.Adapter<FeedGridAdapter.ViewHolder> {
private OnItemClickedListener listener;
private List<FeedItem> mFeedItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public static class ViewHolder extends RecyclerView.ViewHolder{
public LoginTextView ProfileNameCell;
public LoginTextView FeedTimesStampCell;
public NetworkImageView ProfilepicCell;
public LoginTextView FeedStatusMgsCell;
public FeedImageView FeedImageViewCell;
public ViewGroup container;
public ViewHolder(RelativeLayout v){
super(v);
container = v;
ProfileNameCell = (LoginTextView) v.findViewById(R.id.client_name_alternate_cell);
FeedTimesStampCell = (LoginTextView) v.findViewById(R.id.time_stamp_alternate_cell);
ProfilepicCell = (NetworkImageView) v.findViewById(R.id.profile_pic_alternate_cell);
FeedStatusMgsCell = (LoginTextView) v.findViewById(R.id.txtStatusMgs_alternate);
FeedImageViewCell = (FeedImageView) v.findViewById(R.id.feedImage1_alternate);
}
}
public FeedGridAdapter(List<FeedItem> feedItems){mFeedItems = feedItems;}
#Override
public FeedGridAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RelativeLayout v = (RelativeLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.feed_card_alternate, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.ProfileNameCell.setText(mFeedItems.get(position).getName());
CharSequence timeStampCell = DateUtils.getRelativeTimeSpanString(
Long.parseLong(mFeedItems.get(position).getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
holder.FeedTimesStampCell.setText(timeStampCell);
if (!TextUtils.isEmpty(mFeedItems.get(position).getStatus())){
holder.FeedStatusMgsCell.setText(mFeedItems.get(position).getStatus());
holder.FeedStatusMgsCell.setVisibility(View.VISIBLE);
} else {
holder.FeedStatusMgsCell.setVisibility(View.GONE);
}
holder.ProfilepicCell.setImageUrl(mFeedItems.get(position).getImge(), imageLoader);
if (mFeedItems.get(position).getImge() != null){
holder.FeedImageViewCell.setImageUrl(mFeedItems.get(position).getImge(), imageLoader);
holder.FeedImageViewCell.setVisibility(View.VISIBLE);
holder.FeedImageViewCell
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
holder.FeedImageViewCell.setVisibility(View.GONE);
}
holder.container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listener != null)
listener.onItemClicked(holder.getAdapterPosition());
}
});
}
#Override
public int getItemCount() {
return mFeedItems.size();
}
public void setListener(OnItemClickedListener listener){this.listener = listener;}
}
and the expandable fragment is
public class FeedExpandableAdapter extends ExpandablePagerAdapter<FeedItem> {
public FeedExpandableAdapter(List<FeedItem> items){super(items);}
private LayoutInflater inflater;
private Activity activity;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
#Override
public Object instantiateItem(ViewGroup container, int position) {
final ViewGroup rootView = (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.feed_page_alternative, container, false);
if (inflater == null)
inflater = (LayoutInflater)activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
LoginTextView name = (LoginTextView) rootView.findViewById(R.id.profile_name_header);
LoginTextView timestamp = (LoginTextView) rootView.findViewById(R.id.feed_time_stamp_header);
NetworkImageView profilepic = (NetworkImageView) rootView.findViewById(R.id.profile_pic_header_image);
FeedImageView feedImageView = (FeedImageView) rootView.findViewById(R.id.feed_main_image_bottom_sheet);
LoginTextView statusMgs = (LoginTextView) rootView.findViewById(R.id.body_bottom_panel_feed);
name.setText(items.get(position).getName());
CharSequence timeofStamp = DateUtils.getRelativeTimeSpanString(
Long.parseLong(items.get(position).getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
timestamp.setText(timeofStamp);
if (!TextUtils.isEmpty(items.get(position).getStatus())){
statusMgs.setText(items.get(position).getStatus());
statusMgs.setVisibility(View.VISIBLE);
} else {
statusMgs.setVisibility(View.GONE);
}
profilepic.setImageUrl(items.get(position).getProfilePic(), imageLoader);
if (items.get(position).getImge() != null) {
feedImageView.setImageUrl(items.get(position).getImge(), imageLoader);
feedImageView.setVisibility(View.VISIBLE);
feedImageView
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
feedImageView.setVisibility(View.GONE);
}
return attach(container, rootView, position);
}
}
the error shown is like this -
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.telenav.expandablepager.ExpandablePager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
at com.evolustudios.askin.askin.src.fragments.FeedFragmentAlternative.onCreateView(FeedFragmentAlternative.java:86)
can anyone tell me why its returning null?
its possible duplicate, but i cannot figure out why its returning null
xml - feed_card_alternate
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="350dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<it.gmariotti.cardslib.library.view.CardViewNative
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_card_style"
style="#style/card_external">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame_list_card_item_alternate"
android:background="#drawable/cardpanel"
android:paddingTop="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:id="#+id/feed_top_panel_alternate"
android:paddingBottom="25dp">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/profile_pic_alternate_cell"
android:scaleType="fitCenter"
android:paddingTop="15dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="15dp">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/client_name_alternate_cell"
android:textSize="15dp"
android:textStyle="bold"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/time_stamp_alternate_cell"
android:textColor="#color/timestamp"
android:textSize="13dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/feed_other_content_alternate"
android:layout_below="#+id/feed_top_panel_alternate">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtStatusMgs_alternate"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="13dp" />
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtUrl_alternate"
android:linksClickable="true"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/link" />
<com.evolustudios.askin.askin.src.Utils.FeedImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/feedImage1_alternate"
android:background="#80FFFFFF"
android:scaleType="fitXY"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</it.gmariotti.cardslib.library.view.CardViewNative>
feed_activity_alternate.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_wave_swipe_layout_refresh_alternate">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feeds_list_recycler_view"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:scrollbars="vertical"
tools:listitem="#layout/feed_item_list_new">
</android.support.v7.widget.RecyclerView>
<com.telenav.expandablepager.ExpandablePager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bottom_feed_container"
android:layout_gravity="bottom"
app:animation_duration="200"
app:collapsed_height="#dimen/header_height"/>
</jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout>
feed_page_alternative
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#color/pumice">
<include
layout="#layout/feed_header_layout"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250sp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="10dp"
android:id="#+id/feed_bottom_panel_first_container">
<com.evolustudios.askin.askin.src.Utils.FeedImageView
android:layout_width="270sp"
android:layout_height="match_parent"
android:background="#color/edward"
android:id="#+id/feed_main_image_bottom_sheet"
android:scaleType="fitCenter"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scrollbars="none">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/feed_extra_iamge_list_view_bootom_panel">
</ListView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/feed_bottom_panel_second_container"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_very_satisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:src="#drawable/ic_sentiment_satisfied_black_24dp"
android:scaleType="fitCenter"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_neutral_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_dissatisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_sentiment_very_dissatisfied_black_24dp"
android:scaleType="fitCenter"
android:padding="5dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/feed_bottom_panel_third_container"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/very_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/neutral_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/not_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/very_not_liked_number_bottom_panel"
android:text="100"
android:gravity="center"
android:textColor="#color/ming"/>
</RelativeLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/body_bottom_panel_feed"
android:text="Body"
android:textSize="20dp"/>
</ScrollView>
Change,
pager = (ExpandablePager) getActivity().findViewById(R.id.bottom_feed_container);
to
pager = (ExpandablePager) view.findViewById(R.id.bottom_feed_container);
Also change,
final RecyclerView mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feeds_list_recycler_view);
to
final RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.feeds_list_recycler_view);
I am simply trying to show a fragments recyclerView inside it's parent activity. The data is there but nothing is showing up. Any thoughts? Here is PagerAdapter, parent and fragment classes with xmls so that all the parts are available to see. I want the RV to fit right here between the CardView and comment line. Thanks for any help!
PagerAdapter
public class DropPagerAdapter extends FragmentPagerAdapter{
final int PAGE_COUNT = 2;
private String tabTitles[] = new String[] { "Comments", "Riples"};
private Context context;
public DropPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
return CommentFragment.newInstance(position + 1);
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}
Fragment.java
public class CommentFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
private String mDropObjectId;
private String mAuthorId;
private String mAuthorRank;
private String mAuthorName;
private String mAuthorFacebookId;
private String mDropDescription;
private String mRipleCount;
private String mCommentCount;
private Date mCreatedAt;
private String mTabName;
private RecyclerView mRecyclerView;
private TextView mViewDropEmptyView;
private ArrayList<CommentItem> mCommentList;
private CommentAdapter mCommentAdapter;
public static CommentFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
CommentFragment fragment = new CommentFragment();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_comment, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.comment_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mViewDropEmptyView = (TextView) view.findViewById(R.id.comment_empty_view);
Intent intent = getActivity().getIntent();
mDropObjectId = intent.getStringExtra("dropObjectId");
mAuthorId = intent.getStringExtra("authorId");
mAuthorRank = intent.getStringExtra("authorRank");
mAuthorName = intent.getStringExtra("commenterName");
mAuthorFacebookId = intent.getStringExtra("authorFacebookId");
mDropDescription = intent.getStringExtra("dropDescription");
mRipleCount = intent.getStringExtra("ripleCount");
mCommentCount = intent.getStringExtra("commentCount");
mCreatedAt = (Date) intent.getSerializableExtra("createdAt");
mTabName = intent.getStringExtra("mTabName");
loadCommentsFromParse();
return view;
}
public void loadCommentsFromParse() {
final ArrayList<CommentItem> commentList = new ArrayList<>();
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Comments");
query.whereEqualTo("dropId", mDropObjectId);
query.orderByDescending("createdAt");
query.include("commenterPointer");
// query.setLimit(25);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e != null) {
Log.d("KEVIN", "error error");
} else {
for (int i = 0; i < list.size(); i++) {
final CommentItem commentItem = new CommentItem();
ParseObject commenterData = (ParseObject) list.get(i).get("commenterPointer");
//Commenter data////////////////////////////////////////////////////////////
ParseFile profilePicture = (ParseFile) commenterData.get("parseProfilePicture");
if (profilePicture != null) {
profilePicture.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
// Bitmap resized = Bitmap.createScaledBitmap(bmp, 100, 100, true);
commentItem.setParseProfilePicture(bmp);
updateRecyclerView(commentList);
}
}
});
}
//CommenterId
commentItem.setCommenterId(commenterData.getObjectId());
//Commenter Name
commentItem.setCommenterName((String) commenterData.get("displayName"));
//Rank
commentItem.setCommenterRank((String) commenterData.get("userRank"));
//Comment Data/////////////////////////////////////////////////////////////
// DropId
commentItem.setDropId(list.get(i).getString("dropId"));
//Comment
commentItem.setCommentText(list.get(i).getString("commentText"));
//Date
commentItem.setCreatedAt(list.get(i).getCreatedAt());
commentList.add(commentItem);
}
Log.i("KEVIN", "Comment list size: " + commentList.size());
}
}
});
}
private void updateRecyclerView(ArrayList<CommentItem> comments) {
if (comments.isEmpty()) {
mRecyclerView.setVisibility(View.GONE);
mViewDropEmptyView.setVisibility(View.VISIBLE);
}
else {
mRecyclerView.setVisibility(View.VISIBLE);
mViewDropEmptyView.setVisibility(View.GONE);
}
mCommentAdapter = new CommentAdapter(getActivity(), comments);
ScaleInAnimationAdapter scaleAdapter = new ScaleInAnimationAdapter(mCommentAdapter);
mRecyclerView.setAdapter(new AlphaInAnimationAdapter(scaleAdapter));
mRecyclerView.setAdapter(mCommentAdapter);
}
}
Fragment XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/comment_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Primary_Background_Color"
/>
<TextView
android:id="#+id/comment_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal"
android:visibility="visible"
android:text="Post a comment on this Drop!"
android:textSize="18sp"
android:textStyle="italic"
android:foregroundGravity="center"
android:paddingBottom="200dp"
android:textAlignment="center"/>
Parent XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:background="#color/Primary_Background_Color"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:id="#+id/card_view_drop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#FFFFFF"
card_view:cardPreventCornerOverlap="false"
>
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_gravity="bottom"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white"/>
<RelativeLayout
android:id="#+id/click_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="#drawable/custom_bg">
<android.support.v7.widget.Toolbar
android:id="#+id/trickle_card_tool_bar"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#BBDEFB"
/>
<ImageView
android:id="#+id/profile_picture"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_default"
android:background="#drawable/custom_bg"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/profile_picture"
android:width="50dp"
android:text="Kevin Hodges"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp"
android:textColor="#000000"
android:singleLine="true"
android:layout_alignTop="#+id/profile_picture"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_toStartOf="#+id/menu_button"
android:layout_toLeftOf="#+id/menu_button"
android:background="#drawable/custom_bg_blue"
android:clickable="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/comment_created_at"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="September 18, 2015 # 3:32 p.m."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10sp"
android:singleLine="true"
android:background="#drawable/custom_bg"
android:gravity="left"
android:layout_alignBottom="#+id/profile_picture"
android:layout_alignRight="#+id/menu_button"
android:layout_alignEnd="#+id/menu_button"
android:layout_toRightOf="#+id/profile_picture"
android:layout_marginLeft="8dp"
/>
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:focusable="false"
android:maxLines="5"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="false"
android:text="Description"
android:layout_below="#+id/profile_picture"
android:textColor="#color/PrimaryText"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="32dp"
android:background="#drawable/custom_bg"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/menu_button"
android:layout_marginLeft="8dp"
android:src="#drawable/menu_svg"
android:layout_alignBottom="#+id/trickle_card_tool_bar"
android:layout_marginBottom="16dp"
android:background="#drawable/custom_bg_blue"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginRight="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""Mother Teresa""
android:id="#+id/author_rank"
android:textSize="14sp"
android:singleLine="false"
android:gravity="left|center_vertical|center_horizontal"
android:layout_alignLeft="#+id/name"
android:layout_alignStart="#+id/name"
android:textStyle="italic"
android:layout_below="#+id/name"
android:layout_alignBottom="#+id/trickle_card_tool_bar"
android:textColor="#7d000000"
android:layout_toStartOf="#+id/menu_button"
android:layout_marginTop="-4dp"
android:layout_toLeftOf="#+id/menu_button"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<AutoCompleteTextView
android:id="#+id/enter_comment_text"
android:layout_width="235dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/button_post_comment"
android:layout_toLeftOf="#+id/button_post_comment"
android:layout_toRightOf="#+id/post_comment_profile_picture"
android:layout_toStartOf="#+id/button_post_comment"
android:background="#ffffff"
android:hint="#string/write_comment_hint"
android:inputType="textCapSentences|textAutoComplete|textAutoCorrect|text"
android:maxLength="250"
android:paddingLeft="8dp"/>
<ImageView
android:id="#+id/post_comment_profile_picture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:foregroundGravity="center_vertical"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_default"/>
<Button
android:id="#+id/button_post_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:width="50dp"
android:background="#color/AccentColor"
android:text="Post"
android:textColor="#ffffff"/>
I am using ListView inside the row of another ListView. In wishlist.xml, I have one ListView. That items were in wishlist_items.xml, In that wishlist_items also having one more listView. that was designed in wishlist_items_advisors.xml. My problem is that send ListView is showing only one item. Can any one tell me how to fix this?
And the adapters also given below.
wishlist.xml
<LinearLayout
android:id="#+id/logo_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:contentDescription="#string/app_name" />
<LinearLayout
android:id="#+id/title_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/titleredbg"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/wishlist_title"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="#+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
<Button
android:id="#+id/add_person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name"
android:padding="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:text="#string/wishlist_name"
android:textColor="#color/Black" />
<TextView
android:id="#+id/wishlist_email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:text="#string/wishlist_email"
android:textColor="#color/Black" />
</LinearLayout>
<TextView
android:id="#+id/wishlist_relation_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="43"
android:text="#string/wishlist_relation"
android:textColor="#color/Black" />
</LinearLayout>
<LinearLayout
android:id="#+id/items_footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:weightSum="100" >
<ListView
android:id="#+id/listView_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="4dp"
android:visibility="visible" >
</ListView>
<LinearLayout
android:id="#+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/no_data"
android:textColor="#000" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
wishlist_items.xml
<TextView
android:id="#+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#D2D2D2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:ellipsize="end"
android:maxLines="2"
android:text="John John John John John John"
android:textColor="#color/Black" />
<TextView
android:id="#+id/wishlist_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="krishna.mondeddu#gmail.com krishna.mondeddu#gmail.com"
android:textColor="#color/Black" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="43"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_relation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="Birthday Birthday vv Birthday Birthday"
android:textColor="#color/Black" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="40" >
<ImageButton
android:id="#+id/editButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/deleteButton"
android:background="#drawable/wishlistediticon"
android:contentDescription="#string/app_name" />
<ImageButton
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/hr4"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/gift_advisor_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/wishlist_getadvisor"
android:textColor="#color/Black" />
</LinearLayout>
<TextView
android:id="#+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<ListView android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
></ListView>
<TextView
android:id="#+id/hr5"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#fff"
android:paddingTop="5dp"
android:paddingBottom="5dp"
>
<ImageButton
android:id="#+id/invite_advisor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
wishlist_items_advisors.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"
android:background="#fff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/advisor_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:ellipsize="end"
android:maxLines="2"
android:text="John John"
android:textColor="#color/Black" />
<TextView
android:id="#+id/advisor_email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="krishna."
android:textColor="#color/Black" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="43" >
<TextView
android:id="#+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/deleteButton"
android:text="Accept" />
<ImageButton
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
CustomAdapter
public class CustomAdapter extends BaseAdapter{
private String guestIds[]=null;
private String names[]=null;
private String emails[] = null;
private String relationships[] = null;
private String occasions[] = null;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
private Context context=null;
public CustomAdapter(Activity activity,String[] guestId,String[] name,String[] email,String[] relationship, String[] occasion)
{
this.context=activity;
this.guestIds = guestId;
this.names =name;
this.emails = email;
this.relationships = relationship;
this.occasions = occasion;
doption=new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).showStubImage(R.drawable.ic_stub).cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(5)).build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getItemViewType(int position) {
//CustomAdapter item = (CustomAdapter) getItem(position);
if (isItemAnAd(position)) {
return 0;
} else {
return 1;
}
}
private boolean isItemAnAd(int position) {
// Place an ad at the first
return (position == 0);
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items, parent, false);
holder = new ViewHolder();
holder.wishlistName = (TextView) view.findViewById(R.id.wishlist_name);
holder.wishlistEmail = (TextView) view.findViewById(R.id.wishlist_email);
holder.wishlistRelation = (TextView) view.findViewById(R.id.wishlist_relation);
holder.wishGiftAdvisorText = (TextView) view.findViewById(R.id.gift_advisor_text);
holder.advisorListview = (ListView) view.findViewById(R.id.listView);
holder.inviteAdvisor = (ImageButton) view.findViewById(R.id.invite_advisor);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.wishlistName.setText(names[position]);
holder.wishlistEmail.setText(emails[position]);
holder.wishlistRelation.setText(relationships[position]);
holder.wishGiftAdvisorText.setText(getResources().getString( R.string.wishlist_getadvisor)+" "+names[position]+"'s "+getResources().getString( R.string.wishlist_title) );
GuestId = guestIds[position];
holder.wishlistName.setTypeface(tf);
holder.wishlistEmail.setTypeface(tf);
holder.wishlistRelation.setTypeface(tf);
holder.wishGiftAdvisorText.setTypeface(tf);
if(occasions[position].contains("[")) {
try {
array = new JSONArray(occasions[position]);
System.out.println(array.toString(2));
//loadOccasionData(array);
// TODO Auto-generated method stub
if(array!= null) {
advisorIds = new String[array.length()];
advisorNames = new String[array.length()];
advisorEmails = new String[array.length()];
advisorRelationships = new String[array.length()];
advisorStatuses = new String[array.length()];
for (int i = 0; i < array.length(); i++) {
JSONObject c;
try {
c = array.getJSONObject(i);
// Storing each json item in variable
advisorIds[i] = c.getString("advisor_id");
advisorNames[i] = c.getString("name");
advisorEmails[i] = c.getString("email");
advisorRelationships[i] = c.getString("relationship");
advisorStatuses[i] = c.getString("status");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
CustomAdvisorAdapter adapter = new CustomAdvisorAdapter(WishList.this,
advisorIds, advisorNames, advisorEmails, advisorRelationships , advisorStatuses);
holder.advisorListview.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
holder.advisorListview.setAdapter(null);
}
return view;
}
private class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView wishlistName;
public TextView wishlistEmail;
public TextView wishlistRelation;
public TextView wishGiftAdvisorText;
public ListView advisorListview;
public ImageButton inviteAdvisor;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
}
CustomAdvisorAdapter
public class CustomAdvisorAdapter extends BaseAdapter{
private String advisorIds[]=null;
private String advisorNames[]=null;
private String advisorEmails[] = null;
private String advisorRelationships[] = null;
private String advisorStatuses[] = null;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
private Context context=null;
public CustomAdvisorAdapter(Activity activity,String[] advisorId,String[] advisorName,String[] advisorEmail,String[] advisorRelationship, String[] advisorStatus)
{
this.context=activity;
this.advisorIds = advisorId;
this.advisorNames =advisorName;
this.advisorEmails = advisorEmail;
this.advisorRelationships = advisorRelationship;
this.advisorStatuses = advisorStatus;
doption=new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).showStubImage(R.drawable.ic_stub).cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(5)).build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View viewAdvisor = convertView;
final ViewHolder advisorHolder;
if (convertView == null) {
viewAdvisor = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items_advisor, parent, false);
advisorHolder = new ViewHolder();
advisorHolder.advisorNameText = (TextView) viewAdvisor.findViewById(R.id.advisor_name_text);
advisorHolder.advisorEmailText = (TextView) viewAdvisor.findViewById(R.id.advisor_email_text);
advisorHolder.statusText = (TextView) viewAdvisor.findViewById(R.id.status_text);
viewAdvisor.setTag(advisorHolder);
} else {
advisorHolder = (ViewHolder) viewAdvisor.getTag();
}
advisorHolder.advisorNameText.setText(advisorNames[position]);
advisorHolder.advisorEmailText.setText(advisorEmails[position]);
advisorHolder.statusText.setText(advisorStatuses[position]);
advisorHolder.advisorNameText.setTypeface(tf);
advisorHolder.advisorEmailText.setTypeface(tf);
advisorHolder.statusText.setTypeface(tf);
return viewAdvisor;
}
private class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView advisorNameText;
public TextView advisorEmailText;
public TextView statusText;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
}
It's not possible to make a scrollable view inside a scrollable view. But as a work around this, and only in case that this listviews doesn't take much memory if all views are loaded.
you can use this
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class NonScrollableListView extends ListView {
public NonScrollableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Do not use the highest two bits of Integer.MAX_VALUE because they are
// reserved for the MeasureSpec mode
int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightSpec);
getLayoutParams().height = getMeasuredHeight();
}
}
Again, it's not good to use this workaround
you will use this non Scrollable listview in the child.xml layout by adding it as a customized UI component
<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" >
<com.youpackage.uiutils.NonScrollableListView
android:id="#+id/non_scrollable_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
You can ExpandableListView in place of making custom view also for data handling you can use ExpandableListAdapter.