Ich versuche, einen Einstellungsbildschirm zu erstellen, der aus einem Layout mit einigen TextViews und EditText Preference besteht.TextView wird in einem Voreinstellungsfenster überlagert (statt zu überschreiben)
Wenn ich textView.setText (inputString) in der Aktivität verwendet, überschreibt es nicht die vorhandene TextView, sondern erstellt eine neue Kopie von TextView mit inputString als Text und überlappt mit der vorhandenen TextView. Gibt es eine Möglichkeit, dass setText das vorhandene TextView selbst überschreibt?
Dies ist das XML-Layout mit dem Textview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@color/blue"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
></ListView>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:textColor="@color/pseudoBlack"
android:layout_height="wrap_content"
android:layout_marginStart="59dp"
android:layout_marginTop="100dp"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:text="TextView"
android:textColor="@color/pseudoBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_marginStart="100dp" />
<TextView
android:text="TextView"
android:textColor="@color/pseudoBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="43dp"
android:id="@+id/textView11"
android:layout_below="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_marginStart="21dp" />
</RelativeLayout>
Und das ist der Präferenz Bildschirm Ich verwende.
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
>
<Preference android:layout="@layout/inner" android:key="innerkey"
/>
<Preference android:key="mskey"
android:title="show"
/>
<EditTextPreference android:key="editpref"
android:title="Add"
/>
</PreferenceScreen>
Dies ist die Aktivität der Klasse, in der ich setText zu tun versuchen,().
package com.example.asus.layoutcheck;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.widget.TextView;
public class SecondaryActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inner);
TextView txt1 = (TextView)findViewById(R.id.textView2);
TextView txt2 = (TextView)findViewById(R.id.textView5);
TextView txt3 = (TextView)findViewById(R.id.textView11);
txt1.setText("First Text");
txt2.setText("Second Text");
txt3.setText("Third Text");
final String message = "This is the message" ;
addPreferencesFromResource(R.xml.pref);
final Preference msg = findPreference("mskey");
msg.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
msg.setSummary(message);
return true;
}
});
Preference edit = findPreference("editpref");
}
}
Ich habe den Screenshot des Ergebnisses hinzugefügt.
Wie kann ich überwinden dieses Problem? Vielen Dank im Voraus
Es funktionierte nicht. Die App funktioniert nicht mehr, wenn ich die setContentView ersetze. – user6739649