Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:38:31+00:00 2026-06-01T20:38:31+00:00

I have certain problem . I am creating an expendable List with custom tableLayout

  • 0

I have certain problem . I am creating an expendable List with custom tableLayout as child of expendableList. The Table Layput has 1 textView and 3 EditText in each row.

Now , The problem is that the editTexts in TableLayout does not detect text entered at run time. It gives blank value from editText. Please find the attached Code and suggest me suggestion to overcome the problem.

Main problem lies is the editText in gettabledata() methos shows isInEditMode “False”. Can you please help how we can set IsInEditMode “true” at runtime.

package dus.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.ExpandableListActivity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.Layout;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class VarietyDetailsActivity extends ExpandableListActivity {
    TextView tv;

    EditText r1, r2, r3;
    TableLayout table;
    String[] States;
    String year;
    String[] listval = { "Candidate Variety", "Referencer variety 1",
            "Reference Variety 2", "Reference Variety 3" };

    @Override
    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);

        year = getIntent().getStringExtra("year").toString();
        System.out.println("Year in details activity:::::::" + year);
        States = getIntent().getStringArrayExtra("States");

        setContentView(R.layout.variety_details);

        List groupList = new ArrayList();
        Map groupData = new HashMap();
        System.out.println("listval[i]:::::" + "Candidate Variety");
        groupData.put("text2", "Candidate Variety");

        groupList.add(groupData);

        Map groupData1 = new HashMap();
        System.out.println("listval[i]:::::" + "Reference Variety 1");
        groupData1.put("text2", "Reference Variety 1");

        groupList.add(groupData1);

        Map groupData2 = new HashMap();
        System.out.println("listval[i]:::::" + "Reference Variety 2");
        groupData2.put("text2", "Reference Variety 2");

        groupList.add(groupData2);

        Map groupData3 = new HashMap();
        System.out.println("listval[i]:::::" + "Reference Variety 3");
        groupData3.put("text2", "Reference Variety 3");

        groupList.add(groupData3);

        List childList = new ArrayList();
        List childList1 = new ArrayList();
        Map childMap = new HashMap();
        childMap.put("States", "States");
        childMap.put("R1", "R1");
        childMap.put("R2", "R2");
        childMap.put("R3", "R3");
        for (int i = 0; i < States.length; i++) {
            childMap.put(States[i], States[i]);
            // childMap.put("Green", "Green");
            // childMap.put("Purple", "Purple");
        }

        childList1.add(childMap);

        childList.add(childList1);
        childList.add(childList1);
        childList.add(childList1);
        childList.add(childList1);

        String[] str = new String[States.length + 4];
        str[0] = "States";
        str[1] = "R1";
        str[2] = "R2";
        str[3] = "R3";
        for (int j = 0; j < States.length; j++) {
            str[j + 4] = States[j];
        }

        int[] ids = new int[States.length + 4];
        ids[0] = R.id.States;
        ids[1] = R.id.r1;
        ids[2] = R.id.r2;
        ids[3] = R.id.r3;
        for (int j = 0; j < States.length; j++) {
            ids[j + 4] = j;
        }

        for (int i = 0; i < listval.length; i++) {
            System.out.println("listval[i]:::::" + listval[i]);

            // setListAdapter(new ExampleAdapter(this));

            /*
             * SimpleExpandableListAdapter listAdapter = new
             * SimpleExpandableListAdapter (this.getApplicationContext(),
             * groupList,R.layout.grouplayout_collapsed, new String[] {"text2"},
             * new int[] {R.id.text2}, childList,R.layout.childlayout, str,
             * getValue());
             */

            MyAdapter ma = new MyAdapter(this.getApplicationContext(),
                    groupList, R.layout.grouplayout_collapsed,
                    new String[] { "text2" }, new int[] { R.id.text2 },
                    childList, 0, str, ids);
            setListAdapter(ma);

        }

    }

    private class MyAdapter extends SimpleExpandableListAdapter {
        LayoutInflater layoutInflater;
        Context context;

        public MyAdapter(Context context,
                List<? extends Map<String, ?>> groupData, int groupLayout,
                String[] groupFrom, int[] groupTo,
                List<? extends List<? extends Map<String, ?>>> childData,
                int childLayout, String[] childFrom, int[] childTo) {
            super(context, groupData, groupLayout, groupFrom, groupTo,
                    childData, childLayout, childFrom, childTo);
            this.context = getApplicationContext();
            layoutInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        @Override
        public View getChildView(int groupPosition, int childPosition,
                boolean isLastChild, View convertView, ViewGroup parent)

        {
            final int selecetdPos = groupPosition;
            System.out.println("111111111111111111111111111111111111111111");

            convertView = layoutInflater.inflate(R.layout.childlayout, null);
            convertView.setId(R.layout.childlayout);
            table = (TableLayout) convertView.findViewById(R.id.chart);

            System.out.println("TABLe:::::::::::::::" + table);

            TableRow tabrow1 = (TableRow) LayoutInflater.from(
                    VarietyDetailsActivity.this).inflate(
                    R.layout.expandablelist_table_head, null);
            ((TextView) tabrow1.findViewById(R.id.States)).setText("States");
            ((TextView) tabrow1.findViewById(R.id.r1)).setText("R1");
            ((TextView) tabrow1.findViewById(R.id.r2)).setText("R2");
            ((TextView) tabrow1.findViewById(R.id.r3)).setText("R3");
            tabrow1.setVisibility(0);
            System.out.println("TABROW:::::::::::::::" + tabrow1);
            System.out.println("TABLe:::::::::::::::" + table);
            table.addView(tabrow1);

            for (int k = 0; k < States.length; k++) {
                // Inflate your row "template" and fill out the fields.
                TableRow tabrow = (TableRow) LayoutInflater.from(
                        VarietyDetailsActivity.this).inflate(
                        R.layout.expandabletable_data, null);
                System.out.println("TABLe ROW:::::::::::::::" + tabrow);

                ((TextView) tabrow.findViewById(R.id.state1))
                        .setText(States[k]);
                ((TextView) tabrow.findViewById(R.id.state1)).setId(k);

                ((EditText) tabrow.findViewById(R.id.r1_r1val)).setInputType(0);
                ((EditText) tabrow.findViewById(R.id.r1_r1val))
                        .setEditableFactory(new Editable.Factory());

                ((EditText) tabrow.findViewById(R.id.r1_r2val)).setInputType(0);
                ((EditText) tabrow.findViewById(R.id.r1_r2val))
                        .setEditableFactory(new Editable.Factory());

                ((EditText) tabrow.findViewById(R.id.r1_r3val)).setInputType(0);
                ((EditText) tabrow.findViewById(R.id.r1_r3val))
                        .setEditableFactory(new Editable.Factory());

                tabrow.setVisibility(0);
                table.addView(tabrow);

            }

            System.out.println("TABLe ROW COUNTTTTTT:::::::::::::::"
                    + table.getChildCount());

            table.requestLayout();
            table.setVisibility(TableLayout.VISIBLE);

            Button ok = (Button) convertView.findViewById(R.id.ok);
            System.out.println("Butttooonnn:::::" + ok);
            ok.setTextColor(Color.BLACK);
            ok.setTextSize(20);
            ok.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {
                    System.out.println("INSIDE BUTTON ON CLICK:::::");
                    System.out.println("Selecetd POs:::::" + selecetdPos);

                    String[] charValues = getTableData();
                    for (int i = 0; i < charValues.length; i++) {
                        String[] rowValues = charValues[i].split(",");
                        System.out.println("ROW VALUES Length:::::"
                                + rowValues.length);
                        if (selecetdPos == 0)
                            insertinDB(year, rowValues[0],
                                    Constants.characterstic, "candidate",
                                    rowValues[1], rowValues[2], rowValues[3]);
                        else if (selecetdPos == 1)
                            insertinDB(year, rowValues[0],
                                    Constants.characterstic, "referenceVar1",
                                    rowValues[1], rowValues[2], rowValues[3]);
                        else if (selecetdPos == 2)
                            insertinDB(year, rowValues[0],
                                    Constants.characterstic, "referenceVar2",
                                    rowValues[1], rowValues[2], rowValues[3]);
                        else if (selecetdPos == 3)
                            insertinDB(year, rowValues[0],
                                    Constants.characterstic, "referenceVar3",
                                    rowValues[1], rowValues[2], rowValues[3]);
                    }

                }
            });

            return convertView;
        }

        void insertinDB(String year, String state, String characterstic,
                String variety, String r1, String r2, String r3) {
            final DBAdapter dbAdapter = DBAdapter
                    .getDBAdapterInstance(getApplicationContext());
            dbAdapter.openDataBase();
            ContentValues initialValues = new ContentValues();

            if (variety.equals("candidate")) {

                initialValues.put("candidate_varR1", r1);
                initialValues.put("candidate_varR2", r2);
                initialValues.put("candidate_varR3", r3);
            } else if (variety.equals("referenceVar1")) {

                initialValues.put("reference_var1R1", r1);
                initialValues.put("reference_var1R2", r2);
                initialValues.put("reference_var1R3", r3);
            } else if (variety.equals("referenceVar2")) {

                initialValues.put("reference_var2R1", r1);
                initialValues.put("reference_var2R2", r2);
                initialValues.put("reference_var2R3", r3);
            } else if (variety.equals("referenceVar3")) {

                initialValues.put("reference_var3R1", r1);
                initialValues.put("reference_var3R2", r2);
                initialValues.put("reference_var3R3", r3);
            }
            dbAdapter.updateRecordRValuesInDB(initialValues, year,
                    characterstic, state);
            System.out.println("DB Updated");

            dbAdapter.close();
        }

    }

    public String[] getTableData() {
        String[] charValues = new String[States.length];

        for (int j = 0; j < States.length; j++) {

            System.out.println("TABLe:::::::::::::::" + table);

            TableRow tr = (TableRow) table.getChildAt(j + 1);
            tr.setEnabled(true);
            System.out.println("Tablerow:::::" + tr);

            System.out.println("TableRow Count:::::" + tr.getChildCount());
            TextView state = (TextView) tr.getChildAt(0);
            r1 = (EditText) tr.getChildAt(1);
            /*
             * r1.requestFocus(); r1 .setEnabled(true); r1.setFocusable(true);
             * r1.setFocusableInTouchMode(true); r1.setClickable(true);
             * r1.setInputType(InputType.TYPE_CLASS_TEXT);
             * r1.setText(r1.getText(), TextView.BufferType.EDITABLE);
             */
            System.out.println("EditText:::::" + r1);

            System.out.println("EditText enabled :::::" + r1.isEnabled());

            System.out.println("EditText Edit Mode :::::" + r1.requestFocus());
            System.out.println("EditText Edit Mode :::::" + r1.isInEditMode());
            System.out.println("EditText Text :::::" + r1.getEditableText());

            /*
             * r1.setOnEditorActionListener(new
             * EditText.OnEditorActionListener() {
             * 
             * @Override public boolean onEditorAction(TextView arg0, int arg1,
             * KeyEvent arg2) { // TODO Auto-generated method stub if (arg1 ==
             * EditorInfo.TYPE_CLASS_TEXT) { System.out.println("TRUEEEEEEEE");
             * return true;
             * 
             * } System.out.println("FALSEEEEE"); return false;
             * 
             * } }
             * 
             * );
             * 
             * r1.addTextChangedListener(new TextWatcher() {
             * 
             * 
             * @Override public void onTextChanged(CharSequence s, int start,
             * int before, int count) {
             * 
             * // TODO Auto-generated method stub
             * System.out.println("OnText Changed EditText r1 Value:::::::::::::::"
             * +r1.getText().toString());
             * 
             * 
             * }
             * 
             * @Override public void beforeTextChanged(CharSequence s, int
             * start, int count, int after) { // TODO Auto-generated method stub
             * System
             * .out.println("Before   EditText r1 Value:::::::::::::::"+r1.
             * getText().toString()); }
             * 
             * @Override public void afterTextChanged(Editable s) { // TODO
             * Auto-generated method stub
             * System.out.println("After   EditText r1 Value:::::::::::::::"
             * +r1.getText().toString()); } });
             */

            System.out.println("EditText r1 Value:::::::::::::::"
                    + r1.getText().toString());
            r2 = (EditText) tr.getChildAt(2);
            System.out.println("EditText r2 Value:::::::::::::::"
                    + r2.getText().toString());
            r3 = (EditText) tr.getChildAt(3);
            System.out.println("EditText r3 Value:::::::::::::::"
                    + r3.getText().toString());

            charValues[j] = state.getText().toString() + ","
                    + r1.getText().toString() + "," + r2.getText().toString()
                    + "," + r3.getText().toString();

        }
        for (int i = 0; i < charValues.length; i++) {
            System.out.println("charvalue  :::::" + charValues[i]);
        }
        return charValues;

    }

}





thanks and regards
Kajal
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:38:33+00:00Added an answer on June 1, 2026 at 8:38 pm

    Actually , The problem solved by setting the TextWatcher on each EditText in getChildView() instead of getTableData() method while initialising the EditText.Fetch the data and storing the data entered in edittext every time in any other variable. Because getChildView() get reloaded on clicking on the each editText. So the editText value need to be stored in any other variable as well to retrieve the data afterwords.

    example:

    @Override public void beforeTextChanged(CharSequence s, int
    start, int count, int after) { // TODO Auto-generated method stub
    }

                      public void afterTextChanged(Editable s) { // TODO
                          if((s!=null&&s.length()>0)){
    
                            v2 = s.toString();
                            Pattern p = Pattern.compile( "([0-9]*)" );
    
                            Matcher m = p.matcher(v2);
                              System.out.println("v2 :::::" + v2);
    
                              if(stateCount>=States.length)
                                    stateCount =0;
    
                                    else
    
                                    stateCount = stateCount+1;
                              System.out.println("SateCount in v2:::::::::::::::" + stateCount);
                                    insertInV2Array(stateCount,v2);
    
    
                            if(!m.matches())
                            {
    
                                    Toast.makeText(VarietyDetailsActivity.this, "Please enter between 1- 9 only",8 )
                                    .show();
    
    
    
                            }
    
    
                          } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem to order a list by certain rule. Actually i have
I have a problem positioning an element in certain browsers. I'm using the jQuery
I have a problem finding elements in XPath that's contains a certain string ignoring
I have a problem in mysql. I need to fetch certain sets of records
I have a strange problem in my PhoneGap-based android app. On certain screens, the
I have been working on the following problem from this book . A certain
I have a webpage that plays a 'chime' sound when certain events occur. Problem
Here's a problem. Developers have some kind of a task (develop certain feature), which
I have certain PHP class methods that access external variables. These variables are not
I have certain panels on my page that are hidden under certain circumstances. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.