Как получить данные редактирования текста из списка по нажатию кнопки? - PullRequest
0 голосов
/ 05 февраля 2019

У меня есть edittext и кнопка, предположим, EditText, ButtonEdit в просмотре списка, в представлении списка динамически генерируются записи, из которых данные вставляются из ответа сервера.Итак, как я могу нажать кнопку в любой строке и получить это значение edittext (после чего отправить их в другое действие, отредактировать и сохранить их снова)?( я публикую только связанные коды )

activity.java

JSONArray jsonArr = jsonObj.getJSONArray("questionbody");
            for (int i = 0; i < jsonArr.length(); i++) {
                HashMap<String, String> question = new HashMap<>();
                JSONObject jsonObj1 = jsonArr.getJSONObject(i);
                question.put("coursename", jsonObj1.getString("coursename"));
                question.put("subjectname", jsonObj1.getString("subjectname"));
                questionList.add(question);
            }

            ListAdapter adapter = new SimpleAdapter(
                    activity.this, questionList,
                    R.layout.list_item, new String[]{"coursename", "subjectname"}, new int[]{R.id.coursename,
                    R.id.subjectname});

            listviewQuestion.setAdapter(adapter);

activity.xml

<?xml version="1.0" encoding="utf-8"?>
<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="com.it.jumtech.equestion.activity.QuestionListActivity">

    <ListView
        android:id="@+id/listQuestion"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"/>
</RelativeLayout>

list_item.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.it.jumtech.equestion.activity.QuestionListActivity">

<TextView
    android:id="@+id/coursename"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    android:layout_marginLeft="5dp"
    android:layout_marginTop="6dp"
    android:textColor="@color/colorPrimary"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginStart="5dp" />

<TextView
    android:id="@+id/subjectname"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    android:layout_marginTop="6dp"
    android:textColor="@color/colorPrimary"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toRightOf="@+id/coursename"
    android:layout_marginLeft="2dp"
    android:layout_marginStart="2dp" />

<Button
    android:id="@+id/buttonEdit"
    android:layout_width="100dp"
    android:layout_height="38dp"
    android:layout_marginBottom="6dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="6dp"
    android:background="@android:color/holo_red_dark"
    android:text="EDIT"
    android:textAlignment="center"
    android:textColor="@android:color/white"
    android:textStyle="bold"
  app:layout_constraintLeft_toRightOf="@+id/questionbody"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...