EditText can't edit in android ListView - android

Currently working with listview which contains edittext in each row.
The row item xml is below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/result_solution_list_row_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/demo_product_background"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/artist_name_textview"
android:layout_width="#dimen/twohundred"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/home_dark_blue"
android:textSize="#dimen/list_text_size"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/contentLinearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:descendantFocusability="afterDescendants"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="#+id/add_product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="2dp"
android:textColor="#color/home_dark_blue"
android:textSize="#dimen/list_text_size"
android:textStyle="bold" />
<ImageView
android:id="#+id/img_camera"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_margin="2dp"
android:background="#drawable/ic_pre_camera"
android:contentDescription="#string/app_name" />
<ImageView
android:id="#+id/drag_handle"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:layout_margin="2dp"
android:background="#drawable/drag_icon"
android:contentDescription="#string/app_name" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#color/cus_container" >
</LinearLayout>
In this xml, LinearLayout - contentLinearLayout can be inflated a view dynamically.
The inflating view (xml) contains the EditText views.
The following is the inflated xml .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingLeft="#dimen/five"
android:paddingRight="#dimen/five"
>
<TextView
android:id="#+id/artist_name_textview"
android:layout_width="#dimen/hundreadfifty"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/home_dark_blue" />
<LinearLayout
android:layout_width="#dimen/home_hundred"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/home_five"
android:layout_marginRight="#dimen/home_five"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_name_quan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:singleLine="true"
android:text="QUANTITY"
android:textSize="#dimen/list_text_size"
android:textColor="#color/home_dark_blue" />
<EditText
android:id="#+id/txt_quan"
android:layout_width="#dimen/home_eighty"
android:layout_height="match_parent"
android:background="#drawable/edt_blue_background"
android:inputType="numberDecimal"
android:singleLine="true"
android:textColor="#color/home_dark_blue" />
</LinearLayout>
<LinearLayout
android:layout_width="#dimen/nav_drawer_uf_image_width"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_name_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:singleLine="true"
android:text="PRICE"
android:textStyle="bold"
android:textSize="#dimen/list_text_size"
android:textColor="#color/home_dark_blue" />
<EditText
android:id="#+id/txt_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edt_blue_background"
android:inputType="numberDecimal"
android:singleLine="true"
android:textColor="#color/home_dark_blue" />
</LinearLayout>
My problem is , I want both events. 1. ListView's OnItemClickListener 2. EditText should be editable.
I have tried the solutions posted in below links
Trying to catch a click on android ListView item: android:descendantFocusability="blocksDescendants" not working
Android EditText in ListView - keyboard
Focusable EditText inside ListView
http://androidtechnicalblog.blogspot.in/2014/04/quick-trick-of-week-edittext-inside.html
Most of the solutions stressed on android:descendantFocusability attribute.I have tried with different values and set to the listview and listview's root layout alone.
Still the EditTexts are not editable.
Any solutions ?

I have done this with the Imageview earlier.
At that time i put the click listner of Imageview at the Adapter.
I am not sure but may be this will help you.
set this at your adapter
viewHolder.txt_price.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Your Code
}
});
your ListView click event
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// your code
}
});
Not Sure might be help You. Good Luck

Related

Android - TextView's Weight Property in LinearLayout is being ignored when used as ListView row View

I have a CustomListView, when I longClick on a row, the layout of that row changes to a different listRow Layout. So far, everything is working, however, the layout of the new view is compressed. Here are my xml files:
search_result_layout.xml --> this is the original xml file used by the customListView Adapter.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_weight="0.54"
android:layout_marginRight="5dp"
android:layout_height="match_parent"
android:text="Item Name"
android:gravity="center"
android:textSize="10pt" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_weight="0.14"
android:layout_height="match_parent"
android:text="Price"
android:gravity="center"
android:textSize="10pt" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_weight="0.10"
android:layout_height="match_parent"
android:text="Discount"
android:gravity="center"
android:textSize="10pt" />
<TextView
android:id="#+id/qtyInput"
android:layout_width="0dp"
android:layout_weight="0.14"
android:layout_height="match_parent"
android:text="qtyInput"
android:gravity="center"
android:textSize="10pt" />
<TextView
android:id="#+id/discInput"
android:layout_width="0dp"
android:layout_weight="0.11"
android:layout_height="match_parent"
android:text="discInput"
android:gravity="center"
android:textSize="10pt" />
</LinearLayout>
Here is my search_result_inflate.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_weight="0.54"
android:layout_marginRight="5dp"
android:layout_height="match_parent"
android:text="Item Name"
android:gravity="center"
android:textSize="10pt" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_weight="0.14"
android:layout_height="match_parent"
android:text="Price"
android:gravity="center"
android:textSize="10pt" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_weight="0.10"
android:layout_height="match_parent"
android:text="Discount"
android:gravity="center"
android:textSize="10pt" />
<EditText
android:id="#+id/qtyInput"
android:layout_width="0dp"
android:layout_weight="0.14"
android:layout_height="match_parent"
android:hint="qtyInput"
android:inputType="number"
android:gravity="center"
android:textSize="10pt" />
<EditText
android:id="#+id/discInput"
android:layout_width="0dp"
android:layout_weight="0.11"
android:layout_height="match_parent"
android:hint="discInput"
android:inputType="number|date"
android:gravity="center"
android:textSize="10pt" />
</LinearLayout>
The two files are almost identical, only that the last two TextViews become EditTexts instead so the user can input the values he or she wants.
Also, kindly notice that I placed weight in my textViews and EditTexts, so that the spaces are maximized when the user shifts the view from portrait to landscape.
resultListView.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
TextView textViewQuantity = (TextView)view.findViewById(R.id.qtyInput);
TextView textViewDiscountReq = (TextView)view.findViewById(R.id.discInput);
TextView textViewName = (TextView)view.findViewById(R.id.dialogItemName);
TextView textViewPrice = (TextView)view.findViewById(R.id.price);
TextView textViewDiscount = (TextView)view.findViewById(R.id.discount);
textViewQuantity.setVisibility(View.GONE);
textViewDiscountReq.setVisibility(View.GONE);
textViewName.setVisibility(View.GONE);
textViewPrice.setVisibility(View.GONE);
textViewDiscount.setVisibility(View.GONE);
LinearLayout ll_inflate = (LinearLayout)view.findViewById(R.id.search_result_layout);
Log.d("Angelo", "original width = " + ll_inflate.getWidth());
View child = getLayoutInflater().inflate(R.layout.search_result_inflate, null);
TextView newText = (TextView)child.findViewById(R.id.qtyInput);
newText.setText(textViewQuantity.getText().toString());
EditText enter_txt = (EditText)child.findViewById(R.id.qtyInput);
ll_inflate.addView(child);
Log.d("Angelo", "not original width = " + ll_inflate.getWidth());
return false;
}
});
When the I longClick an item, the layout changes. However, the TextViews and the EditTexts are all next to one another, as if the weight property was ignored. At first I thought that the width might have changed before and after the view was changed, but the Log told me it had 1136 width (I'm using a 2nd Gen Nexus 7). Now I'm blank, the width of the parent didn't change but the weight value was ignored. How do I fix this? Would assigning the weight programmatically a viable solution?
Also, follow up question, I only want the last 2 TextViews to change to EditTexts. So what I try to do to achieve that effect is that from the original layout, I pull the values of the first 3 fields (Item Name, Price, Discount) by doing textView.getText().toString() and get the textviews from the new layout and use setText() but so far, it did not work, any suggestions?
UPDATE:
Upon reading this link, I think that the Weight property of the TextViews inside the LinearLayout is being ignored when I use the LinearLayout as my ListView Row View. Nesting another Linear Layout did not help much either.
I placed another LinearLayout inside as such:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="0.70"
android:gravity="center"
android:text="Item Name"
android:textSize="23sp" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.16"
android:gravity="center"
android:text="Price"
android:textSize="23sp" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.12"
android:gravity="center"
android:text="Discount"
android:textSize="23sp" />
<EditText
android:id="#+id/qtyInput"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.16"
android:gravity="center"
android:hint="qtyInput"
android:inputType="number"
android:textSize="23sp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/discInput"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.13"
android:gravity="center"
android:hint="discInput"
android:inputType="number|date"
android:textSize="23sp" />
</LinearLayout>
</LinearLayout>
Any ideas?
Call instead:
ll_inflate.addView(child, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

Image button change to press state when click item in listview in android

I have a list view with customize item, item in list view include: text view and image button, i have set background for image button with a selector. My problem is when i click on item in list view, image button change state to press (click event not trigger), i don't want to this, i want to image button change state to press only when i press on it. Any solution for me? Thanks!
Layout of item row
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#drawable/song_list_selector" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:checked="true"
android:textSize="12sp"
android:textOn="#string/favorite"
android:textOff="#string/favorite"
android:textColor="#drawable/text_color_toggle_button"
android:id="#+id/toggle_favorite"
android:clickable="false"
android:focusable="false"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:checked="false"
android:textSize="12sp"
android:textColor="#drawable/text_color_toggle_button"
android:textOn="#string/offline"
android:textOff="#string/online"
android:id="#+id/toggle_offline"
android:clickable="false"
android:focusable="false"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="10dp"
android:background="#drawable/bg_button_song_menu"
android:contentDescription="#string/song_menu"
android:id="#+id/btn_song_menu"
android:focusable="false"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/toggle_favorite"
android:layout_toLeftOf="#id/btn_song_menu"
android:text="999 Doa Hong"
android:textColor="#0e7491"
android:textSize="20sp"
android:id="#+id/lbl_song_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Nhac chi chuyen xua, da xa roi nhu giac mo..."
android:textSize="12sp"
android:layout_below="#id/lbl_song_name"
android:layout_toLeftOf="#id/btn_song_menu"
android:id="#+id/lbl_song_lyric"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:drawableLeft="#drawable/ic_microphone"
android:drawablePadding="2dp"
android:textSize="12sp"
android:text="1,478"
android:layout_marginTop="5dp"
android:layout_below="#id/lbl_song_lyric"
android:id="#+id/lbl_sing_times"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:drawableLeft="#drawable/ic_save"
android:drawablePadding="2dp"
android:textSize="12sp"
android:text="548"
android:layout_marginTop="5dp"
android:layout_below="#id/lbl_song_lyric"
android:id="#+id/lbl_save_times"/>
</RelativeLayout>
</RelativeLayout>
Layout of listview
<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"
tools:context=".SongListActivity" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:divider="#null"
android:listSelector="#00000000"
android:cacheColorHint="#00000000"
android:id="#+id/list_song"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"
android:id="#+id/lbl_no_song"
android:layout_centerInParent="true"
android:visibility="gone"
android:textColor="#b6b6b6"/>
</RelativeLayout>
As a default, ListView consume all the touch events and just propagate the duplicated status to its children. In order to avoiding this you should set focusable attribute as 'false' in ListView.
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
/>
It happens due to focusability of ImageButton in listitem layout.
Add below line to root layout of your ListView's Item layout.
android:descendantFocusability="blocksDescendants"

Android listview onItemClickListener doesn't work

Please excuse my English, I'm French !
I've got a listview, and I want to display an other activity on click on an item.
But the onItemClickListener seems to doesn't work...
I searched on Google, but but I found nothing.
Here my code:
The XML listView (custom) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_advert_list_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background" >
<RelativeLayout
android:id="#+id/advertBackground"
android:layout_width="339dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="7.5dp"
android:layout_marginTop="7.5dp"
android:background="#drawable/background_advert_list" >
<RelativeLayout
android:id="#+id/advertImageLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" >
<RelativeLayout
android:id="#+id/advertBackgroundLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grey" >
<ImageView
android:id="#+id/advertImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/advertPriceLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/advertImage"
android:layout_marginTop="-30.5dp"
android:background="#color/white_50" >
<TextView
android:id="#+id/advertPriceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="#string/Price"
android:paddingBottom="5dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="3dp"
android:textSize="14dp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/advertInfosLayout"
android:layout_width="305dp"
android:layout_height="47dp"
android:layout_below="#+id/advertImageLayout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<RelativeLayout
android:id="#+id/advertInfosLayoutLayout"
android:layout_width="225dp"
android:layout_height="wrap_content"
android:layout_below="#+id/advertImageLayout" >
<TextView
android:id="#+id/advertTitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/Product_name"
android:textColor="#color/grey_blue"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/advertSizeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/advertTitleText"
android:hint="#string/Product_infos"
android:textColor="#color/b4b5b6"
android:textSize="15sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/advertBookmarkLayout"
android:layout_width="74dp"
android:layout_height="45dp"
android:layout_toRightOf="#+id/advertInfosLayoutLayout" >
<Button
android:id="#+id/advertBookmarkIcon"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_centerVertical="true"
android:background="#drawable/bookmark" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/advertDistanceLayout"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/advertDistanceIcon"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_centerHorizontal="true"
android:background="#drawable/distance" />
<TextView
android:id="#+id/advertDistanceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/advertDistanceIcon"
android:layout_centerHorizontal="true"
android:text="13 km"
android:textColor="#color/grey_midark"
android:textSize="11sp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
The Java code :
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Start new detail activity
Intent intent = new Intent(activity, AdvertDetailActivity.class);
startActivity(intent);
Log.w("AdvertList", "Item clicked");
}
});
Have you got an idea ?
Thanks a lot !
If you're adding buttons/checkboxes to a ListView row, you should add this to them in the xml:
android:focusable="false"
Why? Because you have 2 click zones, the button and the row itself, so you have to put your row as the principal touch zone.
Try that to see if it works.
On the other hand, you have too many ViewGroups (RelativeLayouts) in your xml, which will make the draw process slower. Having only one (and maybe some LinearLayouts if you really need them) should be enough.

CheckBox click in ListView

I have a listview with some text and a checkbox. I can click the checkbox, and the check changes, but when I try to listen for the check being changed, or the click, the listener never triggers.
I have the listview in an Activity (not a ListActivity)
schedule.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/schedulerLayout">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:paddingBottom="10dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/currentHours"
android:textSize="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50dp"
android:text=":"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/currentMinutes"
android:textSize="50dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<!--vertical filler for am/pm display -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ampm"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/currentDayOfWeek"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/currentDate"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scheduleButton"
android:text="#string/newSchedule"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FFFFFFFF"/>
<ListView
android:id="#+id/scheduler_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
schedulerow.xml:
<?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="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/scheduleListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:text="Title"/>
<TextView
android:id="#+id/scheduleListDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scheduleListTitle"
android:text="Days"/>
<TextView
android:id="#+id/scheduleListMonths"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scheduleListDays"
android:text="Months"/>
<View
android:id="#+id/schedulerSeparator"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FFFFFFFF"
android:layout_below="#id/scheduleListMonths"/>
<CheckBox
android:id="#+id/scheduleCheckBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="true"
android:layout_above="#id/schedulerSeparator"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/scheduleListTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/scheduleCheckBox"
android:text="Time"/>
</RelativeLayout>
I'm filling in the data like this:
SimpleAdapter adapter = new SimpleAdapter(this,
data,
R.layout.schedulerow,
new String[] {"Title","Time","Day", "Month"},
new int[] { R.id.scheduleListTitle, R.id.scheduleListTime,R.id.scheduleListDays, R.id.scheduleListMonths});
listView.setAdapter(adapter);
If I try to add a listener to the checkbox, it does nothing. Any suggestions? I've looked through a TON of sample code and similar questions, and none of it seems to work.
One solution is to forget the list item click listener and use another listener for the rest of the item other than the checkbox.. In item layout xml, put the other views in single layout and set the click listener on this and set the check listener on checkbox as usual. Both will work without issues. Dont use the list item click listener.
class MySimpleAdapter extends SimpleAdapter {
...
#Override
void getView(.....) {
View view = super.getView(.....);
view.findViewById(R.id.checkboxid).setOnCheckChangedListner(checklistener);
view.findViewById(R.id.restOfitemview).setOnClickListner(clickListner);
return view;
}
}
Define the two listeners and set as shown above.
Edit : First try your method(blocking focus on checkbox) with the MySimpleAdapter setting only the checkchangelistener.. If that does not work then use above solution of dividing the item layout.

need to show List of items between , top and bottom bar,

I want to create a layout in which two bars , one at top , another at bottom will be there, and one listview between these two bars, But question here is , between the top and bottom bar, i need to show list of items, where both top and bottom bar will be there in their place, only listview will be scrollable.
below is my xml layout , sorry for the lengthy question, Any suggestion will be appreciated. Thanks
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
style="#android:style/ButtonBar"
>
<ImageButton
android:id="#+id/IBADDNEW"
android:layout_width="62dp"
android:layout_height="62dp"
android:src="#drawable/ad_user_l" />
<EditText
android:id="#+id/ETSEARCHTEXT"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/IBSEARCH"
android:layout_width="62dp"
android:layout_height="62dp"
android:src="#drawable/search_64" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
>
<LinearLayout
android:id="#+id/LLforList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity ="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="#+id/IVimageIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/ic_farmer" />
<TextView
android:id="#+id/TVFLNAME"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="Some Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/blankbarbottom"
android:layout_alignParentBottom="true" >
<LinearLayout
android:id="#+id/FLlayoutLIst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btnMainMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/mainmenu_on" />
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/settings_off" />
<ImageButton
android:id="#+id/btnExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/exit_off" />
</LinearLayout>
</RelativeLayout>
Use a ListView for your List. It's scrollable so you don't need a ScrollView. Refer to http://developer.android.com/resources/tutorials/views/hello-listview.html on how to use a simple ListView with an Adapter.
And you should also use a TabHost for your Tabs. Have a look at http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
You can create a Layout that you want to add as the Header and Footer of the ListView and then you can add them to the ListView,
View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();
listView.addHeaderView(header);
listView.addFooterView(footer);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
android.R.id.text1, names));
ithink you can use listView.addheadview and listView.addrootview
edit:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_height="36dip"
android:orientation="horizontal"
android:background="#drawable/cloth_xixian_bg"
android:id="#+id/headclothesroom">
<Button android:id="#+id/redianroom"
android:layout_width="100dip"
android:layout_height="36dip"
android:layout_marginLeft="40dip"
android:background="#null"
android:textSize="18sp"
android:textColor="#drawable/color_wenzi_bg"
android:text="热点排行"/>
<Button android:id="#+id/liangyiroom"
android:layout_width="100dip"
android:layout_height="36dip"
android:textColor="#drawable/color_wenzi_bg"
android:textSize="18sp"
android:background="#null"
android:layout_marginLeft="25dip"
android:text="我的靓衣间" />
<Button android:id="#+id/preButton"
android:layout_width="90dip"
android:layout_height="46dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="9dip"
android:text="前页"
android:layout_marginTop="1dip"
android:background="#drawable/btn_default"
android:textColor="#FFFFFF"
/>
<Button android:id="#+id/midchoth"
android:layout_width="90dip"
android:layout_height="46dip"
android:layout_marginLeft="12dip"
android:background="#drawable/btn_default"
android:layout_marginTop="1dip"
android:textColor="#FFFFFF"
android:visibility="invisible"
android:text="继续"
/>
<Button android:id="#+id/backbu"
android:layout_width="90dip"
android:layout_height="46dip"
android:layout_marginLeft="12dip"
android:background="#drawable/btn_default"
android:layout_marginTop="1dip"
android:textColor="#FFFFFF"
android:text="后页"
/>
</LinearLayout>
You need to Inflate the xml for ListView items. Create new xml say inflate.xml with the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/icon" >
</ImageView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" >
</TextView>
</LinearLayout>
Now in your activity class extend it with ListActivity, and do this
Create string array say "items" with multiple "First L Name"s as given in white screen like
String[] items = {"First L Name","First L Name","First L Name"};
Then,
setContentView(R.layout.main);
setListAdapter(new NewListAdapter(this));
Extend NewListAdapter class with any Adapter like ArrayAdapter and do this
class NewListAdapter extends ArrayAdapter {
Activity context;
NewListAdapter(Activity context) {
super(context, R.layout.inflate,items);
this.context=context;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View row = inflater.inflate(R.layout.inflate, null);
TextView lblName = (TextView) row.findViewById(R.id.textView1);
lblName.setText(items[position]);
return (row);
}
}
Now run your code and see the magic...
I did it my self here is the exact solution for the cause,
in layour i have added one listView
<ListView
android:id="#+id/LVfarmerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
in place of
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
>
<LinearLayout
android:id="#+id/LLforList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity ="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="#+id/IVimageIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/ic_farmer" />
<TextView
android:id="#+id/TVFLNAME"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="Some Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
and created one more layout which is
<LinearLayout
android:id="#+id/LLforList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity ="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="#+id/IVimageIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/ic_farmer" />
<TextView
android:id="#+id/TVFLNAME"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="Some Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
now created one Activity(not listActivity)
in which i showed the layout, which have listview between top and bottom bar.
and created a customAdapter by using another layout, which which have one imageview and textview.
by listview.setAdapter , added this adapter into list view, and it worked for me.

Categories

Resources