2

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 ?

Community
  • 1
  • 1
Karthikeyan Ve
  • 2,550
  • 4
  • 22
  • 40

1 Answers1

0

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

Shubhank Gupta
  • 833
  • 2
  • 15
  • 35