java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7 - android

I am trying to implement view pager,in my view pager images comes from server,I am able to display and scroll but when i reach at last image it shows error and app got crash,following is my snippet code
public class Test_Pager extends Activity{
private String strtd;
String[] imgStr;
ImageView imageView;
ArrayList<String> userImgArrayList;
String[] myURLs;
/*country list*/
JSONArray country_list=null;
private ServiceHandler sh;
private String jsonStr;
private JSONObject jsonObj;
private String user_img;
private String user_pro;
private static String PROFILE_VIEW_URL = "";
private static final String USER_IMG="product_images";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test_pagerss);
userImgArrayList = getIntent().getStringArrayListExtra("user_images");
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
imageView = (ImageView) findViewById(R.id.full_image_view);
PROFILE_VIEW_URL="";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
sh = new ServiceHandler();
// Making a request to url and getting response
jsonStr = sh.makeServiceCall(PROFILE_VIEW_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
try {
jsonObj = new JSONObject(jsonStr);
/*proview_business = jsonObj.getString(PROFILE_VIEW_BUSINESS);
proview_subcat = jsonObj.getString(PROFILE_VIEW_SUB_CATAGORY);
proview_mainpro = jsonObj.getString(PROFILE_VIEW_MAINPRODUCTS);
proview_expr = jsonObj.getString(PROFILE_VIEW_EXPERIENCE);
proview_cmpname = jsonObj.getString(PROFILE_VIEW_COMPANYNAME);
proview_website = jsonObj.getString(PROFILE_VIEW_WEBSITE);*/
// user_img=jsonObj.getString(USER_IMG);
user_img=jsonObj.getString(USER_IMG);
user_img = "";
userImgArrayList = new ArrayList<String>();//declare userImgArrayList globally like ArrayList<String> userImgArrayList;
JSONArray picarray = jsonObj.getJSONArray(USER_IMG);
for(int i=0;i< picarray.length();i++)
{
user_img = picarray.getString(i);
userImgArrayList.add(user_img);
Log.d("mylog", "curent pro pic = " + user_img);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public class ImageAdapter extends PagerAdapter {
Context context;
ImageAdapter(Context context)
{
this.context=context;
}
#Override
public int getCount() {
return USER_IMG.length();
}
#Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.activity_horizontal_margin);
imageView.setPadding(padding, padding, padding, padding);
//imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
//Picasso.with(context).load(userImgArrayList.get(position)).into(imageView);
Picasso.with(context).load(userImgArrayList.get(position)).resize(200, 200) .into(imageView);
/*for(int i=0; i<myURLs.length;i++)
{
try {
url = new URL(myURLs[i]);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
imageView.setImageBitmap(bmp);
}
*/
// imageView.setImageURI(Uri.parse(imgStr[position]));
((ViewPager) container).addView(imageView, 0);
return imageView;
}
}
}
Myxml
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#android:color/white"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="#+id/lnr"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView android:id="#+id/full_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/></LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#drawable/secondpart"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*" android:stretchColumns="*" >
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Product Name"
android:layout_marginLeft="5dp"
android:textColor="#android:color/black"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtageprofile"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
/></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Code"
android:layout_marginLeft="5dp"
android:textColor="#android:color/black"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtheightprofile"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
/></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Purchase Rate"
android:layout_marginLeft="5dp"
android:textColor="#android:color/black"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtmrgprofile"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
/></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp">
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Weight"
android:layout_marginLeft="5dp"
android:textColor="#android:color/black"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtworkingprofile"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
/></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Sales Rate"
android:layout_marginLeft="5dp"
android:textColor="#android:color/black"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtplaceprofile"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
/></TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#drawable/secondpart"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|right"
android:id="#+id/txteatprofile"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

USER_IMG.length(); returns the length of the String (the number of chars of "product_images"). You should return the size of the data set instead. Change
#Override
public int getCount() {
return USER_IMG.length();
}
to
#Override
public int getCount() {
if (userImgArrayList == null) {
return 0;
}
return userImgArrayList.size();
}

change your getcount() method to
#Override
public int getCount() {
int count =0
if (userImgArrayList != null) {
count=userImgArrayList.size();
}
return count;
}
And also add notifyDataSetChanged after filling the arraylist like this..
for(int i=0;i< picarray.length();i++)
{
user_img = picarray.getString(i);
userImgArrayList.add(user_img);
Log.d("mylog", "curent pro pic = " + user_img);
}
adapter.notifyDataSetChanged()

replace,
Picasso.with(context).load(userImgArrayList.get(position)).resize(200, 200) .into(imageView);
with,
try{Picasso.with(context).load(userImgArrayList.get(position)).resize(200, 200) .into(imageView);}catch(Exception e){
e.printStackTrace();}

Related

BaseAdapter returns null [duplicate]

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);

Show fragment recyclerViews in Parent Activity

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"/>

Radio button not visible to android in android fragment

I am fetch data using json and set my spinner and I am also want to add radio button in my operator spinner but radio button not visible and not working I want visible button some Ids but its not visible.
MyXML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rount_corner1"
android:layout_margin="#dimen/activity_horizontal_margin"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginTop="25dp"
android:inputType="number"
android:maxLength="10"
android:textColor="#000000"
android:layout_marginRight="40dp"
android:hint="Enter Mobile number"
android:textColorHint="#000000"
android:layout_marginLeft="40dp"
android:clickable="true"
android:id="#+id/prenumber"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginTop="7dp"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:clickable="true"
android:hint="Enter Recharge Amount"
android:textColorHint="#000000"
android:textColor="#000000"
android:maxLength="4"
android:inputType="number"
android:id="#+id/rechergpre"
/>
<Spinner
android:id="#+id/operator_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:gravity="left"
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="7dp"
android:prompt="#string/appbar_scrolling_view_behavior">
</Spinner>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="38dp"
android:visibility="gone"
>
<RadioButton
android:id="#+id/_TopUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TopUp "
/>
<RadioButton
android:id="#+id/Special"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Special(2G,3G,SMS,VOICE )"
/>
</RadioGroup>
<Button
android:layout_width="match_parent"
android:id="#+id/prepaid_submit"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:text="Submit"
android:textStyle="bold"
android:layout_marginTop="60dp"
/>
</LinearLayout>
</RelativeLayout>
Mycode in Fragment
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
MyApplication myOpt = (MyApplication)getActivity().getApplicationContext();
protected Void doInBackground(Void... params) {
json_data = new ArrayList<Json_Data>();
datalist = new ArrayList<String>();
oprList = new ArrayList<String>();
jsonobject = JSONfunctions
.getJSONfromURL("http://www.example.com");
Log.d("Response: ", "> " + jsonobject);
try {
jsonarray = jsonobject.getJSONArray("data");
for (int i = 0; i < jsonarray.length(); i++) {
jsonobject = jsonarray.getJSONObject(i);
Json_Data opt_code = new Json_Data();
opt_code.setName(jsonobject.optString("name"));
opt_code.setId(jsonobject.optString("ID"));
json_data.add(opt_code);
datalist.add(jsonobject.optString("name"));
oprList.add(jsonobject.getString("ID"));
}
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void args) {
final Spinner mySpinner = (Spinner)getView().findViewById(R.id.operator_spinner);
mySpinner
.setAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_dropdown_item,
datalist));
mySpinner
.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0,
View arg1, int position, long arg3) {
// get Operaotor cod in opt_code field
String opt_code = oprList.get(position);
String selectedItem = arg0.getItemAtPosition(position).toString();
Log.d("Selected operator is==", "======>" + selectedItem);
Log.d("Selected Value is======", "========>" + position);
Log.d("Selected ID is======", "========>" + opt_code);
if(opt_code=="8" || opt_code=="14"|| opt_code=="35"||opt_code=="36"||opt_code=="41"||opt_code=="43")
{
_RadioGroup = (RadioGroup)getView().findViewById(R.id.radioGroup);
_RadioGroup.setVisibility(View.VISIBLE);
mySpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int selectedId = _RadioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
RadioButton _RadioSex = (RadioButton)getView().findViewById(selectedId);
Toast.makeText(getActivity(),
_RadioSex.getText(), Toast.LENGTH_SHORT).show();
}
});
}
String user1 = myOpt.setOperator(opt_code);
String opt_name = myOpt.setOpt_provider(selectedItem);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
Image like:
Please help me, thanks.
Chenge xml like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:id="#+id/operator_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="7dp"
android:gravity="left"
android:textAlignment="center" >
</Spinner>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingLeft="38dp"
android:visibility="gone" >
<RadioButton
android:id="#+id/_TopUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TopUp " />
<RadioButton
android:id="#+id/Special"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Special(2G,3G,SMS,VOICE )" />
</RadioGroup>
</LinearLayout>

single data is getting repeating 18 times in listview

i have an app in which i am retrieving data from json and showing it in listview,i getting an problem only single data is getting visible in the list,i tried to figure out the problem but get nothing,where i am going wrong please help me to sort it out.In log i am getting different data but on adding it to array list getting single data repition multiple time,and no other item is visible.
BussinessActivity
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bussiness_details);
Log.i("DetailsUrl.Bussinessurl", DetailsUrl);
new JSONAsyncTask().execute(DetailsUrl);
weblink=(TextView)findViewById(R.id.txtweb);
list1 = (ListView) findViewById(R.id.list1);
list1.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long id) {
// TODO Auto-generated method stub
//Toast.makeText(getApplication(),
//catagery.get(position).getcategory_name(),
//Toast.LENGTH_LONG).show();
}
});
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(BussinessDetails.this);
dialog.setMessage("Loading, please wait");
dialog.setTitle("Connecting server");
dialog.show();
dialog.setCancelable(false);
catageries = new ArrayList<ProfileDetails>();
}
#Override
protected Boolean doInBackground(String... urls) {
try {
// ------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONObject jarray = jsono.getJSONObject("business");
ProfileDetails category = new ProfileDetails();
//String business_id = jarray.getString("business_id");
//Log.i("business_id", business_id);
//String business_name = jarray.getString("business_name");
//Log.i("business_name", business_name);
String web_site = jarray.getString("web_site");
category.setData1(web_site);
category.setNumber2(web_site);
//weblink.setText(web_site);
Log.i("web_site", web_site);
//String about_business = jarray.getString("about_business");
//Log.i("web_site", web_site);
JSONObject phn = jarray.getJSONObject("Phones");
List<String> listArray = new ArrayList<String>();
Iterator iter = phn.keys();
int count=0;
while(iter.hasNext())
{
String key = (String)iter.next();
// listArray.add((String)iter.next());
Log.i("Name",key);
count +=1;
// String key = (String)iter.next();
// Object o = phn.get(key);
if( phn.get(key) instanceof JSONArray ){
JSONArray arry = phn.getJSONArray(key);
int size = arry.length();
for (int i = 0; i < size; i++) {
String CC_info_left = arry.getJSONObject(i).getString("CC_info_left");
Log.i("CC_info_left", CC_info_left);
String CC_info_right = arry.getJSONObject(i).getString("CC_info_right");
Log.i("CC_info_right", CC_info_right);
String CC_info_short_desc = arry.getJSONObject(i).getString("CC_info_short_desc");
Log.i("CC_info_short_desc", CC_info_short_desc);
String CC_info_short_desc_align = arry.getJSONObject(i).getString("CC_info_short_desc_align");
Log.i("CC_info_short_desc_align", CC_info_short_desc_align);
category.setName(key);
category.setNumber1(CC_info_right);
category.setData(CC_info_left);
category.setDescription(CC_info_short_desc);
// Log.i("category", category.toString());
catageries.add(category);
}
}
}
//Collections.sort(listArray);
// System.out.println(listArray);
JSONObject EmailAddress = jarray.getJSONObject("Emails");
Iterator iter1 = EmailAddress.keys();
int count1=0;
while(iter1.hasNext()){
String key1 = (String)iter1.next();
Log.i("Name1",key1);
count +=1;
// String key = (String)iter.next();
// Object o = phn.get(key);
if( EmailAddress.get(key1) instanceof JSONArray ){
JSONArray arry1 = EmailAddress.getJSONArray(key1);
int size1 = arry1.length();
for (int i = 0; i < size1; i++) {
String CC_info_left1 =arry1.getJSONObject(i).getString("CC_info_left");
String CC_info_right1 = arry1.getJSONObject(i).getString("CC_info_right");
String CC_info_short_desc1 = arry1.getJSONObject(i).getString("CC_info_short_desc");
String CC_info_short_desc_align1 =arry1.getJSONObject(i).getString("CC_info_short_desc_align");
category.setEmail(key1);
category.setEmailleft(CC_info_left1);
category.setEmailright(CC_info_right1);
category.setEmailDesc(CC_info_short_desc1);
catageries.add(category);
}
}
}
// /}
// }
return true;
}
// ------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
//adapter.notifyDataSetChanged();
if (result == false){
Toast.makeText(BussinessDetails.this,
"Unable to fetch data from server", Toast.LENGTH_LONG)
.show();
}else{
adapter = new DetailAdaptor(BussinessDetails.this, R.layout.list_details, catageries);
list1.setAdapter(adapter);
//emailAdaptor=new EmailAdaptor(BussinessDetails.this, R.layout.list_details, catagery);
//list2.setAdapter(emailAdaptor);
}
}
}
DetailAdaptor
public class DetailAdaptor extends ArrayAdapter<ProfileDetails> {
ArrayList<ProfileDetails> detailList;
LayoutInflater vi;
int Resource;
ViewHolder holder;
public DetailAdaptor(Context context, int resource, ArrayList<ProfileDetails> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
detailList = objects;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
if (v == null) {
holder = new ViewHolder();
v = vi.inflate(Resource, null);
holder.tvName = (TextView) v.findViewById(R.id.title_from_phone);
holder.tvData2 = (TextView) v.findViewById(R.id.data_from_phone1);
holder.tvData1 = (TextView) v.findViewById(R.id.data_from_phone2);
holder.tvDescription = (TextView) v.findViewById(R.id.data_from_phone3);
holder.email = (TextView) v.findViewById(R.id.title_for_email);
holder.email_left = (TextView) v.findViewById(R.id.email_left);
holder.email_right = (TextView) v.findViewById(R.id.email_right);
holder.emailDescription = (TextView) v.findViewById(R.id.email_desc);
v.setTag(holder);
}
else{
holder = (ViewHolder) v.getTag();
}
holder.tvName.setText(detailList.get(position).getName());
holder.tvDescription.setText(detailList.get(position).getDescription());
holder.tvData1.setText(detailList.get(position).getNumber1());
holder.tvData2.setText(detailList.get(position).getData());
holder.email.setText(detailList.get(position).getEmail());
holder.email_left.setText(detailList.get(position).getEmailleft());
holder.email_right.setText(detailList.get(position).getEmailright());
holder.emailDescription.setText(detailList.get(position).getEmailDesc());
return v;
}
static class ViewHolder {
public ImageView imageview;
public TextView tvName;
public TextView tvDescription;
public TextView tvData1;
public TextView tvData2;
public TextView email;
public TextView emailDescription;
public TextView email_left;
public TextView email_right;
}
}
ProfileDetails
public class ProfileDetails {
private String title;
private String email;
private String email_left;
private String email_right;
private String email_desc;
private String number1;
private String number2;
private String description;
private String detail1;
private String detail2;
//private String children;
//private String image;
public ProfileDetails() {
// TODO Auto-generated constructor stub
}
public ProfileDetails(String name,String num, String num2, String desc,
String data1, String data2,String emails,String emailleft ,String emailright,String emaildesc) {
super();
title = name;
description = desc;
number1 = num;
number2 = num2;
detail1 = data1;
detail2 = data2;
email =emails;
email_left=emailleft;
email_right=emailright;
email_desc=email_desc;
//this.children = children;
//this.image = image;
}
public String getName() {
return title;
}
public void setName(String name) {
title = name;
}
public String getEmail() {
return email;
}
public void setEmail(String ename) {
email = ename;
}
public String getEmailleft() {
return email_left;
}
public void setEmailleft(String Eleft) {
email_left = Eleft;
}
public String getEmailright() {
return email_right;
}
public void setEmailright(String Eright) {
email_right = Eright;
}
public String getEmailDesc() {
return email_desc;
}
public void setEmailDesc(String Edesc) {
email_desc = Edesc;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getData() {
return detail1;
}
public void setData(String data) {
detail1 = data;
}
public String getData1() {
return detail2;
}
public void setData1(String data) {
detail2 = data;
}
public String getNumber1() {
return number1;
}
public void setNumber1(String num) {
number1 = num;
}
public String getNumber2() {
return number2;
}
public void setNumber2(String num) {
number2 = num;
}
/*public String getSpouse() {
return spouse;
}
public void setSpouse(String spouse) {
this.spouse = spouse;
}
public String getChildren() {
return children;
}
public void setChildren(String children) {
this.children = children;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
*/
}
BussinessDetail.xml
<RelativeLayout 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:background="#android:color/white"
android:orientation="vertical" >
<View
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_above="#+id/rel1"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Start a New ChaBu"
android:textColor="#030303"
android:textSize="12dp" />
<ImageView
android:id="#+id/chatIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="#drawable/new_chabu_icon" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel1"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/line"
android:layout_marginTop="5dp"
android:scrollbars="none"
android:textColor="#android:color/black"
tools:listitem="#layout/list_details" >
</ListView>
</RelativeLayout>
List_details
<?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="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rel2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/line"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Customer Care Numbers"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line4"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel2"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/txtlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/line4"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title_from_phone"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text=""
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line3"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_above="#+id/rel1"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="#+id/txtlay"
android:background="#E6E6E6" >
<TextView
android:id="#+id/data_from_phone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/data_from_phone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/data_from_phone3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/data_from_phone1"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:text="" />
</RelativeLayout>
<View
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_above="#+id/whitelay"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<LinearLayout
android:id="#+id/whitelay"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_below="#+id/rel1"
android:background="#android:color/white"
android:orientation="vertical" >
</LinearLayout>
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/line1"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/whitelay"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Customer Care Emails"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line5"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel3"
android:layout_marginTop="10dp"
android:visibility="gone"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/txtlay1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="#+id/line5"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title_for_email"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text=""
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line6"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/txtlay1"
android:visibility="gone"
android:layout_marginTop="0dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:visibility="gone"
android:layout_below="#+id/line6"
android:background="#E6E6E6" >
<TextView
android:id="#+id/email_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/email_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="#+id/email_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/email_left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel5"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/rel4"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/title5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="About Us"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/line9"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/title5"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
</RelativeLayout>
<View
android:id="#+id/line11"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel5"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/rel6"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/line10"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#E6E6E6" >
<TextView
android:id="#+id/about_us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Website"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/line10"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/rel6"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rel5"
android:layout_marginLeft="10dp"
android:layout_marginTop="18dp"
android:visibility="gone"
android:text="ffdhjggjhkkghjg"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/line10"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/txt"
android:layout_marginTop="10dp"
android:visibility="gone"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/txtweb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rel6"
android:layout_marginLeft="10dp"
android:layout_marginTop="18dp"
android:text="ffdhjggjhkkghjg"
android:visibility="gone"
android:textColor="#030303"
android:textSize="15dp"
android:textStyle="bold" />
<View
android:id="#+id/line12"
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/txtweb"
android:visibility="gone"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
</RelativeLayout>
You create Object of category once in pre execute and then you not create new object so the category last value set in the array list everytime you create category object in loop and try it is working

ListView row containing another ListView

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.

Categories

Resources