-4

我知道这已经发布了无数次,我很抱歉,但我试图遵循解决方案,但似乎无法修复它。

基本上我正在尝试从 Android SQLite 数据库中读取记录,但我一直在setText.

public class Landing extends AppCompatActivity{

    public Button buttonProducts;

    public void countRecords(){

        int recordCount = new TableControllerAppointments(this).count();

        ScrollView textViewRecordCount = findViewById(R.id.textViewRecordCount);
        textViewRecordCount.setText(recordCount + " records found.");

    }

我正在学习教程,并将此代码添加到我的 XML 文件中,

<ScrollView
    android:id="@+id/textViewRecordCount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:padding="1dp"
    android:text="@string/textViewRecordCount"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.182"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/buttonCreateAppointment"
    app:layout_constraintVertical_bias="0.146" >

    <LinearLayout
        android:id="@+id/linearLayoutRecords"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    </LinearLayout>

</ScrollView>

抱歉,如果我没有正确发布这是我的第一次。我认为这与我的 ScrollView 有关,但不确定,任何帮助将不胜感激

谢谢

4

3 回答 3

0

您正在尝试为“Scrollview”设置文本,这是绝对错误的。滚动视图是在应用程序运行时用于滚动布局的视图。要完全满足您的要求,您必须声明一个 TextView。然后你可以为它设置文本。

于 2018-03-23T13:08:48.147 回答
0

如何解决方法'setText(java.lang.String)

供参考

setText() is method of textviewnot a method ofScrollview因为ScrollView没有任何setText()

你不能用作Scrollview.setText("Nilesh");

textview.setText("Nilesh");
于 2018-03-23T12:28:02.043 回答
0

应该是这样的 我希望

public Button buttonProducts;
    public void countRecords(){
        int recordCount = new TableControllerAppointments(this).count();

        TextView textViewRecordCount = findViewById(R.id.textViewRecordCount);
        textViewRecordCount.setText(String.ValueOf(recordCount) + " records found.");
}

不能将文本设置为Scrollview,首先你要明白这一点,这是基本的

于 2018-03-23T12:38:03.020 回答