how fix when i click on the twelve item from gridview - android

i have a problem, all items before the number twelve is ok, but starting on twelve when i click on that item and the next items return open the new activity but with other position , i mean when i click on the item number twelve , return me the value number three.
this is my code
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
objAllBean=arrayOfLatestVideo.get(position);
int pos=objAllBean.getId();
Intent intplay=new Intent(getActivity(),VideoPlay.class);
intplay.putExtra("POSITION", pos);
intplay.putExtra("VIDEO_ID", allArrayVideo);
intplay.putExtra("VIDEO_CATNAME", allArrayVideoCatName);
intplay.putExtra("VIDEO_CATID", allArrayVideoCatId);
intplay.putExtra("VIDEO_URL", allArrayVideourl);
intplay.putExtra("VIDEO_NAME", allArrayVideoName);
intplay.putExtra("VIDEO_CID", allArrayVideoId);
intplay.putExtra("VIDEO_DURATION", allArrayVideoDuration);
intplay.putExtra("VIDEO_DISCRIPTION", allArrayVideoDesc);
intplay.putExtra("VIDEO_IMAGE_URL",allArrayImageUrl);
startActivity(intplay);
}
Layout Grid
<FrameLayout 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="#drawable/gradient"
android:gravity="center"
android:id="#+id/rootlayout"
android:orientation="vertical" >
<GridView
android:id="#+id/lsv_latest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="#integer/columns" <-- 3
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:clickable="true"
android:stretchMode="columnWidth">
</GridView>
</FrameLayout>
item gridview
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:paddingTop="5dp"
android:paddingRight="3dp">
<ImageView
android:id="#+id/picture"
android:src="#drawable/ic_launcher"
android:contentDescription="#string/desc"
android:layout_width="match_parent"
android:layout_height="170dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="5dp">
<TextView
android:id="#+id/text_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#ffffff"
android:background="#009ACC"
android:padding="2dp"
android:layout_marginTop="4dp"
android:textSize="10dp"
/>
<TextView
android:id="#+id/second"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textSize="1dp"
/>
<TextView
android:id="#+id/text"
android:text="HD"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="120dp"
android:background="#9a000000"
android:layout_height="22dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#android:color/white"
/>
</LinearLayout>
</FrameLayout>

Related

Horizontal recycler view on top of vertical recycler veiw

This is the individual item's layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#DDE6EC"
tools:context="com.example.personal.newsfeeder.MainActivity">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/section_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="16dp"
android:id="#+id/card_view"
android:layout_gravity="center"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="10dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/avatar_section"
android:layout_width="match_parent"
android:layout_height="72dp"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/circular_image"
android:id="#+id/avatar_image"
/>
<TextView
android:id="#+id/avatar_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/avatar_image"
android:layout_marginLeft="4dp"
tools:text="Title"
android:textStyle="bold"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#616161"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/avatar_name"
android:layout_toRightOf="#id/avatar_image"
android:layout_marginLeft="4dp"
tools:text="Subhead"
android:id="#+id/avatar_subhead"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#616161"/>
</RelativeLayout>
<ImageView
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:src="#drawable/placeholder"
android:id="#+id/image_view"
android:scaleType="centerCrop"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:text="Keep Moving"
android:paddingLeft="16dp"
android:textAppearance="?android:textAppearanceMedium"
android:textAllCaps="true"
android:textStyle="bold"
android:id="#+id/the_title"
/>f
<TextView
android:id="#+id/the_three_lines"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:padding="16dp"
tools:text="#string/description"
android:ellipsize="end"
android:lineSpacingMultiplier="1.2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/heart_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/heart"
android:padding="8dp"
/>
<ImageView
android:id="#+id/bookmark_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bookmark"
android:padding="8dp"
/>
</LinearLayout>
</LinearLayout>
enter code here
</android.support.v7.widget.CardView>
</LinearLayout>
This is the recycler's Adapter code
#Override
public void onBindViewHolder(ArticleViewHolder holder, int position) {
holder.mAvatarView.setText(mArticles.get(position).getmAvatarInitial());
holder.mAvatarNameView.setText(mArticles.get(position).getmAvatarName());
holder.mAvatarSubView.setText(mArticles.get(position).getmAvatarSub());
mRowIndex++;
if (position == 0) {
holder.horizontalList.setLayoutManager(new LinearLayoutManager(holder.context, LinearLayoutManager.HORIZONTAL, false));
holder.horizontalAdapter = new SectionRVAdapter(holder.context);
holder.horizontalList.setAdapter(holder.horizontalAdapter);
holder.horizontalAdapter.setDataset(holder.sections);
}
String imageUrl = mArticles.get(position).getmImageURL();
Picasso.with(mContext)
.load(imageUrl)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error_img)
.into(holder.mImageView);
holder.mTheTitleView.setText(mArticles.get(position).getmTheTitle());
holder.mTheThreeLinesView.setText(mArticles.get(position).getmTheThreeLines());
}
Now i want a horizontal recycler view over the vertical recycler view. But at present the horizontal recycler view is repeated after every 5 cardviews.
I am checking if position is equal to 0 in my onBindViewHolder method but still why is it created multiple times?
I hope i made my question clear.
holder.setIsRecyclable(false);
Add this line in public void onBindViewHolder(ArticleViewHolder holder, int position) {}
I hope this will help you

Android ListView onScroll Fires Multiple Times

I have two views in my fragment. In the first view, I have a linear layout, which holds some controls and in the second view, I have a listview.
I want the linear layout in the first view to be collapsed / expand when I scroll up / down listview.
I tried to handle scroll up / down events of listview in the OnScrollListener and collapse / expand the listview.
But there is a problem with the onScroll method,i.e, when I scroll the listview, it fires many times when I scroll the listview one time. So expanding and collapsing process of linear layout is going crazy.
Here is - what is happening on the screen.
https://www.youtube.com/watch?v=U7KNwS6JlUk
What am I doing wrong?
What is the best way to handle scrol up / down events of listview and collapse / expand linear layout?
My Layout
<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"
tools:context="com.training.mehmetyilmaz.mywallet.TransactionsActivity.TransactionsFragment"
android:orientation="vertical">
<LinearLayout
android:id="#+id/transactions_filter_linear_layout"
android:layout_width="match_parent"
android:layout_height="160dp"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/blue">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/account_type_label"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<RadioGroup
android:id="#+id/transactions_account_type_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="#+id/transactions_rd_cash"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/cash"
android:checked="true"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white" />
<RadioButton
android:id="#+id/transactions_rd_bank"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/bank"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white"
/>
</RadioGroup>
</LinearLayout><!-- Money Add Type-->
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/currency_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<Spinner
android:id="#+id/transactions_spinner_currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/entry_currency"
android:layout_gravity="right"
android:gravity="right|end"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
style="#style/DropDownColor"
android:background="#drawable/abc_spinner_mtrl_am_alpha"
>
</Spinner>
</LinearLayout><!-- Currency -->
</LinearLayout><!-- First Line-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/cyan_ligth"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
>
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/money_type_label"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<RadioGroup
android:id="#+id/transactions_money_type_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="#+id/transactions_rd_add"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/add"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white" />
<RadioButton
android:id="#+id/transactions_rd_sub"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/subtract"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white" />
</RadioGroup>
</LinearLayout><!-- Money Type-->
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/entry_date_label_all_dates"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<Spinner
android:id="#+id/transactions_spinner_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/entry_date"
android:layout_gravity="right"
android:gravity="right|end"
android:textSize="#dimen/transactions_filter_text"
style="#style/DropDownColor"
android:background="#drawable/abc_spinner_mtrl_am_alpha">
</Spinner>
</LinearLayout><!-- Date -->
</LinearLayout><!-- Second Line -->
</LinearLayout><!-- Filter -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.training.mehmetyilmaz.mywallet.ScrollDetectingListView
android:layout_width="match_parent"
android:layout_height="320dp"
android:id="#+id/transactions_list_view"
></com.training.mehmetyilmaz.mywallet.ScrollDetectingListView>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/transactions_total_textView"
android:text="#string/total"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textSize="#dimen/abc_text_size_medium_material"
android:background="#color/green"
android:textColor="#color/white"
android:gravity="center"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</LinearLayout>
OnScrollListener
mTransactionListView.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
//Log.d("Scroll State", "State : " + scrollState);
}
private int mInitialScroll = 0;
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d("Scroll", "Called");
int scrolledOffset = mTransactionListView.getVerticalScrollOffset();
if (scrolledOffset != mInitialScroll) {
boolean scrollUp = (scrolledOffset - mInitialScroll) < 0;
if (scrollUp) {
Log.d("Scroll", "Up");
expand(mTransactionsFilterLinearLayout);
} else {
Log.d("Scroll", "Down");
collapse(mTransactionsFilterLinearLayout);
}
mInitialScroll = scrolledOffset;
}
}
});
I think the solution is not possible with the classic ListView of Android SDK.
I found a custom ListView called Android-ObservableScrollView and implemented it in my project and the result is success.
You can find it from here
https://github.com/ksoichiro/Android-ObservableScrollView/
try setting a booolean value like this as global.
boolean flag = true;
then
if (scrollUp) {
if(flag == false){
Log.d("Scroll", "Up");
expand(mTransactionsFilterLinearLayout);
}
flag = true;
} else {
if(flag == true){
Log.d("Scroll", "Down");
collapse(mTransactionsFilterLinearLayout);
}
flag = false;
}

How to remove list view item in list view android?

In my application i have one custom list view. whenever i click the close image list item, the list item layout must be removed with space. i used visibility:gone attribute, the list item layout deleted but the space is visible. I am using listview in scroll view ,,that was also not working....please help me out.
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.recharge_listitem, null);
TextView accountnumber = (TextView) convertView
.findViewById(R.id.accountnumber);
TextView servicename = (TextView) convertView
.findViewById(R.id.servicetypname);
TextView planamount = (TextView) convertView
.findViewById(R.id.rechargeamount);
final ImageView close = (ImageView) convertView
.findViewById(R.id.crosse_close_img);
final LinearLayout layoutrecharge=(LinearLayout)convertView.findViewById(R.id.rechargelay);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
layoutrecharge.setVisibility(View.GONE);
}
});
accountnumber.setText("Rs."+bpData.get(position).getAccountNumber());
servicename.setText(bpData.get(position).getServicename());
planamount.setText(bpData.get(position).getRechargeamount());
return convertView;
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e365a">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:text="PAYMENT"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:text="Your Recharges"
android:textColor="#1e365a"
android:textSize="20dp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#drawable/dottedline_view" />
<ListView
android:id="#+id/recharge_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</ListView>
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginTop="12dp"
android:background="#1e365a" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Amount to be Paid"
android:textColor="#1e365a"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Rs.130"
android:textColor="#1e365a"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="#+id/ev_b_dob"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bt_apply"
style="#style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="20"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp">
<CheckBox
android:id="#+id/cb_reload_cash"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay using Reload Cash"
android:textColor="#1e365a"
android:textSize="20dp"
android:layout_marginLeft="12dp"/>
</LinearLayout>
<Button
android:id="#+id/atmdebit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="ATM/DEBIT/CREDIT"
android:textColor="#ffffff"
android:textSize="20dp"/>
<Button
android:id="#+id/netbankng_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="NET BANKING"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
please help me.
custom listview item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rechargelay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/accountnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8008505106" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="(" />
<TextView
android:id="#+id/servicetypname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vodafone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=")" />
</LinearLayout>
<TextView
android:id="#+id/rechargeamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RS.30"
android:layout_weight="1" />
<ImageView
android:id="#+id/crosse_close_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/close"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Set View.GONE for View is not right way to remove row from ListView. to remove row remove select row item from Adapter data-source and call notify data change method of adapter to populate changes:
close.setTag(position);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int deletePos=Integer.parseInt(v.getTag().toString());
bpData.remove(deletePos);
notifyDataSetChanged();
}
});
Set visibility View.GONE of SCROLL VIEW or other parent of list view....

Listview click listener not responding

I have a list view and want to perform clickable event on it. I did it before. but now its not working. I have added my XML as well. I just need to move from one actvity to other on click in list view.
CustomFinalSubmit_ItemDetail item = new CustomFinalSubmit_ItemDetail(Final_Submit.this , R.layout.customview_finalsubmit_itemdetails, itemInfo);
itemList.setAdapter(item);
itemList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
FinalSubmitItem pos = itemInfo.get(position);
String itemType = pos.getItemType();
String itemCountry = pos.getItemCountry();
String itemSerial = pos.getItemNo();
pos.setChecked(true);
Intent inn = new Intent(getApplicationContext(), FinalSubmitDetails.class);
inn.putExtra("itemType", itemType);
inn.putExtra("itemCountry", itemCountry);
inn.putExtra("itemSerial", itemSerial);
startActivity(inn);
}
});
Here is my main Xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/green">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_marginTop="10dip"
android:orientation="vertical"
android:background="#0B3B0B">
<ListView
android:id="#+id/CustomerDetailList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/yellow"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:id="#+id/Itemtype"
android:paddingTop="5dp"
android:background="#color/green"
android:textColor="#color/yellow"
android:layout_marginLeft="5dip"
android:text="Item Type"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingTop="5dp"
android:id="#+id/txtcountry"
android:background="#color/green"
android:textColor="#color/yellow"
android:text="Country"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingTop="5dp"
android:id="#+id/txtItemNumber"
android:background="#color/green"
android:textColor="#color/yellow"
android:text="Item No."/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:id="#+id/itemChck"
android:button="#drawable/custom_checkbox"
android:paddingTop="5dp"
android:padding="5dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_margin="5dp"
android:layout_height="1dp"
android:background="#color/white"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/itemList"
android:background="#088A08"
android:divider="#color/white"
android:dividerHeight="1dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I did it this way:
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
your code
}});
Just add this much code to my customview
Recently I had the same problem after adding a ToggleButton to my list items. The solution for me was to add android:descendantFocusability="blocksDescendants" to the layout of the item.
Here is the whole 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="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:paddingLeft="15dp"
android:descendantFocusability="blocksDescendants" >
<TextView
android:id="#+id/watch_roadName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Addresse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ToggleButton
android:id="#+id/watch_button_arrived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/watch_roadName"
android:layout_alignParentRight="true"
android:textOn="#string/arrived"
android:textOff="#string/arrived"
android:text="#string/arrived" />
</RelativeLayout>
Similar answers to the same issue can be found here:
How to fire onListItemClick in Listactivity with buttons in list?
and here
Android custom ListView with ImageButton is not getting focus
in the widgets(Textview or button whatever it is) of your inflator layout just add:
android:focusable="false"
android:focusableInTouchMode="false"
and in parent layout of your inflator add:
android:descendantFocusability="blocksDescendants"

how to use item click listner twice in a listview in android

i have a list view which shows 3 headings id , name and type and at last there is a line of checkbox what i want is
if i click value of 1st three heading it should be open in a drill down one more listview while when i check my checkbox which is at last only checkbox is checked no other action should take place
my code s here as below
sfreport.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#EFEFF7"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="ID" android:width="80dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" style="#style/hdrListing" android:height="25sp" />
<TextView android:text="Name" android:layout_weight="1.0" android:layout_width="wrap_content"
android:layout_height="fill_parent" style="#style/hdrListing" android:height="25sp" />
<TextView android:text="Type" android:width="80dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" style="#style/hdrListing" android:height="25sp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:paddingRight="2px" android:background="#000000"
android:layout_width="fill_parent" android:layout_height="2px" android:orientation="horizontal">
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7">
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="#id/android:list"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7"
android:choiceMode="multipleChoice" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="bottom"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="#+id/ll6" />
</LinearLayout>
while my other xml where i set the value is
<?xml version="1.0" encoding="utf-8"?>
<SRTekBox.Android.SRSD.widget.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:DRST="http://schemas.android.com/apk/res/SRTekBox.Android.SRSD" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#color/list_bg">
<TextView android:id="#+id/itemID" android:width="80dip"
android:layout_centerVertical="true" android:textColor="#000000" android:focusable="false"
android:layout_width="wrap_content" android:layout_height="fill_parent" />
<TextView android:id="#+id/itemCaption" android:layout_weight="1.0"
android:layout_centerVertical="true" android:textColor="#000000" android:focusable="false"
android:layout_width="wrap_content" android:layout_height="fill_parent"/>
<TextView android:id="#+id/itemType" android:width="80dip" android:gravity="center"
android:layout_centerVertical="true" android:textColor="#000000" android:focusable="false"
android:layout_width="wrap_content" android:layout_height="fill_parent"/>
<SRTekBox.Android.SRSD.widget.InertCheckBox android:id="#+id/itemCheckBox"
android:layout_width="19dip" android:layout_height="fill_parent" android:focusable="false"
android:layout_centerVertical="true" android:button="#drawable/checkbox" android:width="19px" />
</SRTekBox.Android.SRSD.widget.CheckableLinearLayout>
this is my java code--->
/* public void onListItemClick(ListView parent,View v,int position,long id){
TextView t=(TextView)v.findViewById(R.id.itemID);
TextView t4=(TextView)v.findViewById(R.id.itemCaption);
TextView t5=(TextView)v.findViewById(R.id.itemType);
String sID="";
String sName="";
String SType="";
sID = t.getText().toString();
sName = t4.getText().toString();
SType=t5.getText().toString();
//v.setBackgroundColor(Color.rgb(119,136,153));
if("".equals(sID) || "MY VISIT SUMMARY".equals(sDesc)){
return;
}
if("0".equals(sName)){
return;
}
if("SA-E".equals(SType)){
Intent intent=new Intent(this,SRSDReportsDrillDown.class);
startActivity(intent);
}
}*/
public void onListItemClick(ListView parent,View v,int position,long id){
try{
if(listView.isItemChecked(position)){
int idx=position;
Integer listCount=listView.getCount();
for(Integer xx=0;xx<listCount;xx++){
if(idx==xx){
listView.setItemChecked(xx,true);
popup();
}
else{
}
return;
}
}
}
catch(Exception ex){
MsgBox1(this,ex.toString());
}
}

Categories

Resources