How to Show custom Dialog at center - android

I have a custom dialog for my android application.it shows an image and text with two buttons at left and right.Here is my dialog
public class GalleryPopUp extends Dialog {
private Context context;
private ArrayList<Bitmap> bitmapList = null;
private List<News> homeNewsList = null;
private Button btnArrowLeft;
private Button btnArrowRight;
private ImageView imageView;
private int selectedIndex = 0;
private TextView textView;
static final RelativeLayout.LayoutParams FILL = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
public GalleryPopUp(Context context, ArrayList<Bitmap> bitmapList,
List<News> homeNewsList, int selectedIndex) {
super(context, android.R.style.Theme_Translucent_NoTitleBar);
this.context = context;
this.bitmapList = bitmapList;
this.homeNewsList = homeNewsList;
this.selectedIndex = selectedIndex;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.gallery_popup, null);
btnArrowLeft = (Button)view.findViewById(R.id.btnArrowLeft);
btnArrowRight = (Button)view. findViewById(R.id.btnArrowRight);
imageView = (ImageView) view.findViewById(R.id.imageView);
textView = (TextView)view. findViewById(R.id.textView);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageBitmap(bitmapList.get(selectedIndex));
News news = homeNewsList.get(selectedIndex);
textView.setTextSize(15);
textView.setTypeface(TypeFaceUtils.TYPEFACE_THOOLIKA);
textView.setText(news.getNewsTitle());
btnArrowLeft.setOnClickListener(listenerbtnArrowLeft);
btnArrowRight.setOnClickListener(listenerbtnArrowRight);
setContentView(view);
}
private android.view.View.OnClickListener listenerbtnArrowLeft = new android.view.View.OnClickListener() {
#Override
public void onClick(View v) {
selectedIndex = selectedIndex - 1;
if (selectedIndex < homeNewsList.size() && selectedIndex >= 0) {
imageView.setImageBitmap(bitmapList.get(selectedIndex));
News news = homeNewsList.get(selectedIndex);
textView.setTypeface(TypeFaceUtils.TYPEFACE_THOOLIKA);
textView.setText(news.getNewsTitle());
}
else
{
GalleryPopUp.this.dismiss();
}
}
};
private android.view.View.OnClickListener listenerbtnArrowRight = new android.view.View.OnClickListener() {
#Override
public void onClick(View v) {
selectedIndex = selectedIndex + 1;
if (selectedIndex < homeNewsList.size()) {
imageView.setImageBitmap(bitmapList.get(selectedIndex));
News news = homeNewsList.get(selectedIndex);
textView.setTypeface(TypeFaceUtils.TYPEFACE_THOOLIKA);
textView.setText(news.getNewsTitle());
}
else
{
GalleryPopUp.this.dismiss();
}
}
};
}
gallery_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_gravity="center_horizontal|bottom"
android:gravity="center_horizontal"
android:text=""
android:textColor="#000000" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView"
android:gravity="center" >
<Button
android:id="#+id/btnArrowRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/btn_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView"
android:gravity="center" >
<Button
android:id="#+id/btnArrowLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/btn_arrow_left" />
</LinearLayout>
</RelativeLayout>
How can i show this dialog exactly at center of parent.?

The best way is to change your layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
try it and let me know if it works.
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_gravity="center_horizontal|bottom"
android:gravity="center_horizontal"
android:text=""
android:textColor="#000000" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView"
android:gravity="center" >
<Button
android:id="#+id/btnArrowRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/btn_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView"
android:gravity="center" >
<Button
android:id="#+id/btnArrowLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/btn_arrow_left" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

Related

RecyclerView is not calling onCreateViewHolder method while getItemCount is called

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.

ListView is showing only 1 data while there are 3 records coming in the listview adapter

I want a listview in a tabhost. My data is coming from the database. Through retrofit, I am getting 3 records from the database. I am passing these 3 records to the ListView Adapter that I have created. These records are coming till the constructor of Adapter but after that in the getView method only 1 record is accessed 3 times. I am not sure why this is happening.
This is my Post Activity:
public static final ArrayList<WorkProfilePojo> mProfiles = new ArrayList<>();
BaseURL baseURL = new BaseURL();
VendorPostAdapter pAdapter;
ListView mPostList;
public List<WorkProfilePojo> returnedList = new ArrayList<>();
String lv_vendorId = null;
public static String lv_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
lv_vendorId = intent.getStringExtra("lv_vendorId");
Log.e("vendor id", lv_vendorId);
lv_name = intent.getStringExtra("lv_name");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
getRetrofit();
}
private void getRetrofit() {
Retrofit retrofit = new RetrofitObject().getRetrofit();
final WorkProfileforPostTabAPI mProfileAPI =
retrofit.create(WorkProfileforPostTabAPI.class);
final Call<ArrayList<WorkProfilePojo>> mCall =
mProfileAPI.getWork(lv_vendorId);
mCall.enqueue(new Callback<ArrayList<WorkProfilePojo>>() {
#Override
public void onResponse(Call<ArrayList<WorkProfilePojo>> call,
Response<ArrayList<WorkProfilePojo>> response) {
mProfiles.clear();
returnedList = (ArrayList<WorkProfilePojo>)response.body();
WorkProfilePojo wp;
Log.e("Teste2",
returnedList.get(0).getLv_eventSubCategory());
for (int i = 0; i<= returnedList.size()-1; i++){
wp=new WorkProfilePojo();
wp.setLv_vendorWorkId(returnedList.get(i).getLv_vendorWorkId());
wp.setLv_eventSubCategory(returnedList.get(i).getLv_eventSubCategory());
wp.setLv_workDescription(returnedList.get(i).getLv_workDescription());
wp.setLv_numWorkLikes(returnedList.get(i).getLv_numWorkLikes());
wp.setLv_numWorkComments(returnedList.get(i).getLv_numWorkComments());
mProfiles.add(wp);
Log.e("retrofit profile size: ",
String.valueOf(mProfiles.size()));
populateListView(mProfiles);
}
#Override
public void onFailure(Call<ArrayList<WorkProfilePojo>> call,
Throwable t) {
Log.e(TAG, "FAIL");
}
});
}
private void populateListView(ArrayList<WorkProfilePojo> mProfiles) {
mPostList = (ListView) findViewById(R.id.listVPost);
Log.e("func prof size: ", String.valueOf(mProfiles.size()));
pAdapter = new VendorPostAdapter(this, mProfiles, lv_name);
mPostList.setAdapter(pAdapter);
}
This is my Adapter:
public class VendorPostAdapter extends BaseAdapter {
Context context;
ArrayList<WorkProfilePojo> lv_profiles = new ArrayList<>();
String lv_name;
LayoutInflater inflater;
public VendorPostAdapter(Context context, ArrayList<WorkProfilePojo>
lv_profiles, String lv_name){
this.context = context;
this.lv_profiles =lv_profiles;
this.lv_name = lv_name;
Log.e("adapter name", lv_name );
Log.e("adapter workid", lv_profiles.get(0).getLv_vendorWorkId());
Log.e("adapter workid", lv_profiles.get(1).getLv_vendorWorkId());
Log.e("adapter workid", lv_profiles.get(2).getLv_vendorWorkId());
}
private class ViewHolder {
TextView mtxtViewPartnerName;
TextView mtxtViewEventCategory;
TextView mtxtViewDate ;
TextView mtxtViewFillDescription;
GridView mgrdViewPhotos ;
ImageView mimgLike ;
ImageView mimgPostProfilePic ;
ImageView mimgShare ;
ImageView mimgComment ;
ImageView mimgLikeThumb ;
TextView mtxtNoOfLikes ;
TextView mtxtNoOfComments ;
TextView mtxtComments;
}
#Override
public int getCount() {
return lv_profiles.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
inflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.content_post, parent,
false);
holder = new ViewHolder();
holder.mtxtViewPartnerName = (TextView)
convertView.findViewById(R.id.txtViewPartnerName);
holder.mtxtViewEventCategory= (TextView)
convertView.findViewById(R.id.txtViewEventCategory);
holder.mtxtViewDate = (TextView)
convertView.findViewById(R.id.txtViewDate);
holder.mtxtViewFillDescription = (TextView)
convertView.findViewById(R.id.txtViewFillDescription);
holder.mgrdViewPhotos = (GridView)
convertView.findViewById(R.id.grdViewPhotos);
holder.mimgLike = (ImageView)
convertView.findViewById(R.id.imgLike);
holder.mimgPostProfilePic = (ImageView)
convertView.findViewById(R.id.imgPostProfilePic);
holder.mimgShare = (ImageView)
convertView.findViewById(R.id.imgShare);
holder.mimgLikeThumb = (ImageView)
convertView.findViewById(R.id.imgLikeThumb);
holder.mimgComment = (ImageView)
convertView.findViewById(R.id.imgComment);
holder.mtxtNoOfLikes = (TextView)
convertView.findViewById(R.id.txtViewNoOfLikes);
holder.mtxtNoOfComments = (TextView)
convertView.findViewById(R.id.txtViewNoOfComments);
holder.mtxtComments = (TextView)
convertView.findViewById(R.id.txtViewComments);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
final WorkProfilePojo wp = lv_profiles.get(position);
Log.e("getView name", lv_name );
Log.e("getView workid",
lv_profiles.get(position).getLv_vendorWorkId());
holder.mtxtViewPartnerName.setText( lv_name );
holder.mtxtViewEventCategory.setText( wp.getLv_eventSubCategory() );
FormatDate lv_date = new FormatDate();
holder.mtxtViewDate.setText(lv_date.formatDayMonDateYr(wp.getLv_creationDate()));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription());
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription());
holder.mimgLikeThumb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,
VendorWorkLikesActivity.class);
intent.putExtra("lv_workId", wp.getLv_vendorWorkId());
Log.e("postad workid", wp.getLv_vendorWorkId());
context.startActivity(intent);
}
});
holder.mtxtComments.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,
VendorWorkCommentActivity.class);
context.startActivity(intent);
}
});
return convertView;
}
}
This is my activity_post.xml wrapped in relative layout
<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="#color/backgroundcolour"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="1"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
/>
</RelativeLayout>
This is my content_post for line item wrapped in relative layout:
<RelativeLayout
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgPostProfilePic"
android:src="#drawable/profileicon"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="#+id/txtViewPartnerName"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_toEndOf="#id/imgPostProfilePic"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:text="partner Name" />
<TextView
android:id="#+id/txtViewManageWork"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:layout_marginTop="5dp"
android:text="Managed" />
<TextView
android:id="#+id/txtViewEventCategory"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="220dp"
android:paddingRight="5dp"
android:layout_marginTop="5dp"
android:text="" />
<TextView
android:id="#+id/txtViewEvent"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_toEndOf="#id/txtViewEventCategory"
android:layout_marginTop="5dp"
android:text="Event" />
<TextView
android:id="#+id/txtViewDate"
style="#style/InputLable"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
android:text="Date" />
<TextView
android:id="#+id/txtViewDescription"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="80dp"
android:text="Work Description" />
<TextView
android:id="#+id/txtViewFillDescription"
style="#style/InputLable"
android:layout_width="330dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:text="XYZ" />
<TextView
android:id="#+id/txtViewPhotos"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="130dp"
android:text="Photos" />
<GridView
android:id="#+id/grdViewPhotos"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:numColumns="auto_fit"
android:layout_below="#id/txtViewPhotos">
</GridView>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="#+id/divider"
android:background="#color/colorDarkGray"
android:layout_below="#id/grdViewPhotos"
android:layout_weight="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dividerlayout"
android:orientation="horizontal"
android:layout_below="#id/divider"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ImageView
android:id="#+id/imgLikeThumb"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_below="#id/grdViewPhotos"
android:clickable="true"
android:src="#drawable/likethumb" />
<TextView
android:id="#+id/txtViewNoOfLikes"
style="#style/InputLable"
android:layout_width="30dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:textAlignment="center"
android:layout_marginTop="5dp"
android:text="0" />
<TextView
android:id="#+id/txtViewNoOfComments"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="5dp"
android:textAlignment="center"
android:text="0" />
<TextView
android:id="#+id/txtViewComments"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:text="Comments" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="#+id/divider1"
android:background="#color/colorDarkGray"
android:layout_below="#id/dividerlayout"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dividerlayout1"
android:layout_below="#id/dividerlayout"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/imgLike"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/divider1"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/likeicon2" />
<TextView
android:id="#+id/txtViewLike"
style="#style/InputLable"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Likes" />
<ImageView
android:id="#+id/imgShare"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="60dp"
android:layout_below="#id/divider1"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/shareicon3" />
<TextView
android:id="#+id/txtViewShare"
style="#style/InputLable"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Share" />
<ImageView
android:id="#+id/imgComment"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="45dp"
android:layout_below="#id/divider1"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/commenticon" />
<TextView
android:id="#+id/txtViewComment"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Comment" />
</LinearLayout>
</RelativeLayout>
From retrofit results, I am getting 3 records from database:
func workid:: W00000000000013
func workid:: W00000000000014
func workid:: W00000000000015
But in getView() method I am getting only 1 record coming 3 times:
Likesad name: W00000000000013
Likesad name: W00000000000013
Likesad name: W00000000000013
holder.mtxtViewDate.setText(lv_date.formatDayMonDateYr(wp.getLv_creationDate(getPostion())));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription(getPostion()));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription(getPostion()));
This Might work.

ListView Not Clickable or LongClickable

I have a custom listview but can't manage Click and LongClick on that
this is XML of ListActivity :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#id/activity_main_l2"
android:layout_marginTop="44dp"
android:layout_gravity="bottom"
android:gravity="bottom">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/main"
android:layout_gravity="center"
android:gravity="bottom"
android:visibility="visible"
android:id="#id/activity_main_search_layer">
<EditText android:id="#id/activity_main_search_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/message_field"
android:hint="#string/Search_hint"
android:textColor="#color/textFieldColor"
android:layout_gravity="center"
android:maxLines="8"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:textSize="14dp"
android:singleLine="true"/>
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#00000000"
android:background="#ffffff"
android:fastScrollAlwaysVisible="true"
android:fastScrollEnabled="true"
android:listSelector="#00000000"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:longClickable="true"/>
</LinearLayout>
<include layout="#layout/header1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/include"/>
<include layout="#layout/draver_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/include1"/>
</FrameLayout>
and this is XML of ListRow :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="#fafafa"
android:gravity="end"
android:orientation="horizontal"
android:id="#id/list_row_rl"
android:padding="5dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants" >
<LinearLayout
android:orientation="vertical"
android:layout_width="70dp"
android:layout_height="fill_parent"
android:layout_weight="0"
android:focusable="false"
android:focusableInTouchMode="false">
<FrameLayout
android:layout_width="70dp"
android:layout_height="fill_parent"
android:foregroundGravity="center"
android:layout_gravity="center"
android:focusable="false"
android:focusableInTouchMode="false">
<FrameLayout
android:id="#+id/thumbnail"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="3dp" android:layout_gravity="center"
android:foregroundGravity="center"
android:focusable="false"
android:focusableInTouchMode="false">
<QuickContactBadge
android:id="#+id/quickContactBadge1"
android:layout_width="52dp"
android:layout_height="52dp"
android:scaleType="fitCenter"
android:layout_gravity="center"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/round_frame"
android:layout_gravity="center"
android:gravity="center"
android:focusable="false"
android:focusableInTouchMode="false">
</LinearLayout>
</FrameLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/rounded_counter"
android:layout_gravity="bottom|left"
android:layout_marginLeft="4dp"
android:layout_marginBottom="10dp"
android:id="#id/list_row_number_of_new_sms_layer"
android:visibility="invisible"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="#+id/Numberofsms"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="420"
android:textColor="#FFFFFF"
android:textSize="10dp"
android:textIsSelectable="false"
android:singleLine="true"
android:gravity="center"
android:layout_gravity="center"
android:textColorHighlight="#000000"
android:autoText="false"
android:layout_marginLeft="4dp"
android:layout_marginTop="3dp"
android:layout_marginRight="5dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#id/list_row_click_button"
android:background="#fafafa"
android:focusable="false"
android:focusableInTouchMode="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#id/list_row_click_layer">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="68dp"
android:id="#id/list_row_l1"
android:gravity="right|top"
android:layout_gravity="left|top"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center|left|top"
android:layout_marginRight="5dp"
android:gravity="left|top"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="left|top"
android:gravity="left|top"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="#+id/ContactName"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.60"
android:text="#string/ContactName"
android:textColor="#666666"
android:textSize="16dp"
android:textStyle="bold"
android:typeface="sans"
android:textAlignment="gravity"
android:layout_gravity="left|top"
android:layout_marginRight="5dp"
android:gravity="left|top"
android:phoneNumber="true"
android:layout_marginLeft="5dp"
android:maxHeight="40dp"
android:singleLine="true"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#id/list_row_count"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_gravity="left|top"
android:gravity="left|top"
android:textSize="16dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<TextView
android:id="#+id/LastSMS"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:text="سلام امروز روز خوبی است."
android:textColor="#aeaeae"
android:textSize="12dp"
android:singleLine="true"
android:layout_marginRight="5dp"
android:phoneNumber="false"
android:layout_marginLeft="5dp"
android:layout_marginBottom="2dp"
android:linksClickable="true"
android:autoLink="web"
android:layout_gravity="center_vertical|left"
android:gravity="center|left"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#f34323"
android:focusable="false"
android:focusableInTouchMode="false">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="70dp"
android:layout_height="fill_parent"
android:layout_weight="0"
android:layout_gravity="top"
android:gravity="top"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="68dp"
android:foregroundGravity="left|top"
android:orientation="vertical"
android:layout_gravity="center|top"
android:gravity="center|top"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/list_row_draft_text"
android:id="#+id/list_row_draft_textview"
android:layout_gravity="right"
android:textSize="8dp"
android:textColor="#ff00ac"
android:visibility="invisible"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="#+id/Date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5:45"
android:textColor="#aeaeae"
android:textSize="11dp"
android:gravity="center_vertical"
android:layout_gravity="right"
android:layout_marginBottom="10dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#f34323"
android:id="#+id/linearLayout"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
and in ListActivity :
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
some code...
}
});
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
some code...
}
});
but non of these listener get Click or LongClick
just LongClock on one of the TextView(android:id="#+id/ContactName") work
The Adapter :
public class Adapter extends ArrayAdapter<BoxInfoObject> implements Filterable {
public Adapter(Context c, int resource, int layout, ArrayList<BoxInfoObject> d) {
super(c, resource);
this.c = c;
mOrigionalValues = new ArrayList<BoxInfoObject>(d);
mObjects = new ArrayList<BoxInfoObject>(d);
}
private static class ViewHolder {
public LinearLayout L0;
public TextView NAME, LAST, NUMBEROF, DATE, DRAFT, NUMBEROFNEW;
public QuickContactBadge Badge;
public LinearLayout L1, L2;
public int position;
public ListView list;
}
public void add(BoxInfoObject object) {
mOrigionalValues.add(object);
this.notifyDataSetChanged();
}
public Filter getFilter() {
if (mFilter == null) {
mFilter = new CustomFilter();
}
return mFilter;
}
public int getCount() {
return mObjects.size();
}
public BoxInfoObject getItem(int position) {
return mObjects.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position2, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
vi = LayoutInflater.from(c).inflate(R.layout.list_row, null, false);
holder.L1 = (LinearLayout) vi.findViewById(R.id.list_row_l1);
holder.L0 = (LinearLayout) vi.findViewById(R.id.list_row_rl);
holder.DATE = (TextView) vi.findViewById(R.id.Date);
holder.Badge = (QuickContactBadge) vi
.findViewById(R.id.quickContactBadge1); // thumb image
holder.list = (ListView) parent.findViewById(R.id.list);
,...
vi.setTag(holder);
} else
holder = (ViewHolder) vi.getTag();
holder.position = position2;
BOX = mObjects.get(holder.position);
int APIlevel = android.os.Build.VERSION.SDK_INT;
if (APIlevel > 11)
new load(holder, position2)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
else
new load(holder, position2).execute();
return vi;
}
private class load extends AsyncTask<ViewHolder,
Void, Void> {
private final int p;
private ViewHolder h;
private String holder_NAME_string;
private int holder_l2_visible;
private String holder_NUMBEROFNew_string;
private BoxInfoObject BOX;
private QuickContactHelper QCH;
private QuickContactBadge Badge;
private String holder_Date;
private inboxQuickAction quickAction;
private String holder_text;
public load(ViewHolder holder, int p) {
this.h = holder;
this.p = p;
}
#Override
protected void onPreExecute() {
}
#Override
protected void onPostExecute(Void aVoid) {
if (h.position == p) {
h.DATE.setText(holder_Date);
if (holder_NUMBEROFNew_string != null)
if (holder_NUMBEROFNew_string.length() > 0)
h.L2.setVisibility(holder_l2_visible);
else
h.L2.setVisibility(View.GONE);
else
h.L2.setVisibility(View.GONE);
h.NUMBEROFNew.setText(holder_NUMBEROFNew_string);
notifyDataSetChanged();
}
}
#Override
protected Void doInBackground(ViewHolder... arg0) {
try {
h.DATE.setTypeface(h.font);
h.NUMBEROF.setTypeface(h.font);
h.NAME.setTypeface(h.font);
BOX = mObjects.get(p);
holder_text = BOX.getSmses().get(BOX.getSmses().size() - 1).getMessage();
holder_Date = MakeBox.StringDate(c,
BOX.get().get(BOX.get().size() - 1).getMyDate(), H);
if (BOX.getPNs().size() == 1)
QCH = new QuickContactHelper(c,
BOX.getPNs().get(0), BOX.getOPNs().get(0));
else
QCH = new QuickContactHelper(c);
try {
QCH.BadgeImage2(h.Badge, false);
Badge = QCH.getbadge();
Badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
} catch (Exception e) {
}
if (BOX.getPNs().size() == 1) {
holder_NAME_string = QCH.getname();
if (holder_NAME_string == null) {
Badge.setImageResource(R.drawable.unknown);
} else {
if (QCH.holder.tId == null || QCH.holder.tId == 0)
Badge.setImageResource(R.drawable.personal);
}
} else {
Badge.setImageResource(R.drawable.multiplus);
}
int nons = BOX.getNNew();
if (nons > 0) {
holder_l2_visible = View.VISIBLE;
holder_NUMBEROFNewSMS_string = nons + "";
} else {
holder_l2_visible = View.GONE;
holder_NUMBEROFNewSMS_string = "";
}
} catch (Exception e) {
}
return null;
}
}
any suggestion ?

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.

UI in Graphical Layout and in device are not the same [Android]

ListView in Graphical Layout is fit on appropriate height but when i imported into android device, ListView is reduced in a small field. i want ListView are the same in Graphical Layout in xml file and in real device screen
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10sp"
android:id="#+id/header"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/id"
android:layout_weight="1.25"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/amount"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/alert"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/detail"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="10sp"></ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<Button
android:id="#+id/addQueue"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:text="#string/addQueue"/>
<Button
android:id="#+id/submit"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:text="#string/submit"/>
<Button
android:id="#+id/reset"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/addQueue"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="#string/resetQueue" />
</RelativeLayout>
I have tried to modify your layout. Try this may be it will be helpful for you.. just create a new xml layout file and check it is working for you or not.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/addQueue"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/submit"
android:text="addQueue" />
<Button
android:id="#+id/submit"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="submit" />
<Button
android:id="#+id/reset"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="resetQueue" />
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.25"
android:gravity="center"
android:text="text1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text2" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text3" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text4" />
</LinearLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/addQueue"
android:layout_alignParentLeft="true"
android:layout_below="#+id/header" >
</ListView>
</RelativeLayout>
My custom adapter class is here. :
public class my_custom_adapter extends ArrayAdapter<String> {
private Context context = null;
String[] elements = null;
private ArrayList<Boolean> itemChecked = null;
public my_custom_adapter(Context context, int type, String[] elements2)
{
super(context, type, elements2);
this.elements = elements2;
this.context = context;
itemChecked = new ArrayList<Boolean>();
BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("master_check_change")) {
boolean check_value = intent.getBooleanExtra("check_value", false);
set_checked(check_value);
notifyDataSetChanged();
}
}
};
context.registerReceiver(receiver, new IntentFilter("master_check_change"));
set_checked(false);
}
// AS EVERY TIME LISTVIEW INFLATE YOUR VIEWS WHEN YOU MOVE THEM SO YOU NEED TO SAVE ALL OF YOUR CHECKBOX STATES IN SOME ARRAYLIST OTHERWISE IT WILL SET ANY DEFAULT VALUE.
private void set_checked(boolean is_checked)
{
for (int i=0; i < elements.length; i++) {
itemChecked.add(i, is_checked);
}
}
//THIS IS SIMPLY A CLASS VIEW WILL HOLD DIFFERENT VIEWS OF YOUR ROW.
static class ViewHolder
{
public TextView tv;
public CheckBox cb;
public ImageView iv;
}
#Override
public View getView (final int position, View convertView, ViewGroup parent)
{
View rowView = convertView;
ViewHolder holder = null;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
// HERE I AM INFLATING LISTVIEW LAYOUT.
rowView = inflater.inflate(R.layout.inflated_layout, null, false);
holder = new ViewHolder();
holder.cb = (CheckBox) rowView.findViewById(R.id.checkBox1);
holder.tv = (TextView) rowView.findViewById(R.id.textView1);
holder.iv = (ImageView) rowView.findViewById(R.id.imageView1);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
if (holder != null) {
holder.tv.setText(elements[position]);
holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
itemChecked.set(position, isChecked);
}
});
if(position < itemChecked.size()) {
holder.cb.setChecked(itemChecked.get(position));
}
}
return rowView;
}
}
My activity class is here where i am create custom adapter object,
public class Test_stflowActivity extends Activity {
public CheckBox master_cb = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp_layout);
String[] elements = new String[10];
for (int i = 0; i < 10; i++) {
elements[i] = "elements " + i;
}
CheckBox master_cb = new CheckBox(getApplicationContext());
master_cb.setText("Check All");
//HERE IS THE LIST VIEW WHICH I HAVE CREATED IN MY XML FILE.
ListView lv = (ListView) findViewById(R.id.listView1);
//HERE I AM CREATING CUSTOM ADAPTER OBJECT.
my_custom_adapter adapter = new my_custom_adapter(this, android.R.layout.simple_list_item_1, elements);
lv.addHeaderView(master_cb);
lv.setAdapter(adapter);
master_cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Intent my_intent = new Intent("master_check_change");
my_intent.putExtra("check_value", isChecked);
sendBroadcast(my_intent);
}
});
}
}

Categories

Resources