В моей активности есть ListView, строки которого заполняются логинами, извлеченными из базы данных.Каждая строка в моем ListView содержит один TextView внутри макета ограничения.Когда пользователь касается одной из строк этого ListView, должно быть запущено другое действие.Я использовал OnItemClickListener для достижения этой цели, и все, кажется, работает нормально, но метод onClickItem () из Listener получает ссылку на объект типа ConstraintLayout, и мне нужно получить текст из TextView внутри этого макета.Как я могу это сделать?
Вот мой 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">
<TextView
android:id="@+id/row"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:text="TextView"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
А вот моя реализация OnItemClickListener:
private AdapterView.OnItemClickListener myItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TextView currentView = (TextView) view; // Here I get an exception that ConstraintLayout cannot be casted to TextView
String login = currentView.getText().toString();
Intent intent = new Intent(Powitanie.this,UserPanel.class);
intent.putExtra(LOGIN, login);
Powitanie.this.startActivity(intent);
}
};