2015-02-15 2 views
-1

У меня есть следующая XMLДинамически создавать одну строку таблицы или TextView для каждого SharedPreference?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="none" 
    tools:context="info.senyk.ustat3.StatActivity" 
    android:layout_above="@+id/editTextLogin" 
    android:background="#ffff2341" 
    android:id="@+id/scrollView"> 


</ScrollView> 
<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Login" 
    android:id="@+id/buttonLogin" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginLeft="0dp" 
    android:layout_marginStart="55dp" 
    android:layout_marginRight="0dp" 
    android:layout_marginBottom="0dp" 
    android:onClick="onClickButtonLogin" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextLogin" 
    android:ems="4" 
    android:hint="@string/Login" 
    android:layout_above="@+id/buttonLogin" 
    android:layout_alignLeft="@+id/scrollView" 
    android:layout_alignStart="@+id/scrollView" 
    android:inputType="text" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextAt" 
    android:hint="\@" 
    android:editable="false" 
    android:enabled="false" 
    android:inputType="none" 
    android:layout_below="@+id/scrollView" 
    android:layout_toLeftOf="@+id/editTextHostname" 
    android:layout_toStartOf="@+id/editTextHostname" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextHostname" 
    android:hint="@string/Hostname" 
    android:layout_below="@+id/scrollView" 
    android:layout_toLeftOf="@+id/editTextColon" 
    android:layout_toStartOf="@+id/editTextColon" 
    android:inputType="text" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextColon" 
    android:hint="@string/Colon" 
    android:layout_below="@+id/scrollView" 
    android:layout_toLeftOf="@+id/editTextPort" 
    android:layout_toStartOf="@+id/editTextPort" 
    android:inputType="none" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextPort" 
    android:text="@string/Port22" 
    android:inputType="number" 
    android:layout_below="@+id/scrollView" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextPassword" 
    android:ems="4" 
    android:hint="@string/Password" 
    android:layout_below="@+id/scrollView" 
    android:layout_toRightOf="@+id/editTextColon0" 
    android:layout_toLeftOf="@+id/editTextAt" 
    android:layout_toStartOf="@+id/editTextAt" 
    android:inputType="textPassword" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editTextColon0" 
    android:hint="@string/Colon" 
    android:layout_below="@+id/scrollView" 
    android:layout_toRightOf="@+id/editTextLogin" 
    android:layout_toEndOf="@+id/editTextLogin" 
    android:inputType="none" /> 

У меня есть три editText для входа, пароль и Hostname и кнопку Вход

В верхней части экрана, у меня есть ScrollView и мне нужно сохранить учетные данные. Но я хочу сохранять все отдельные имена хостов (например, историю) каждый раз, когда пользователь нажимает кнопку входа в систему.

Я имею в виду, что для каждой учетной записи требуется динамическое создание одной строки таблицы или TextView?

Любые идеи?

+0

Что относительно [AutoCompleteTextView] (http://developer.android.com/reference/ Android/виджет/AutoCompleteTextView.html)? – WojciechKo

ответ

0

Это не Spinner лучше для этого? Он может быть настроен для того, чтобы иметь больше строки текста.

Для вашего текущего макета я хотел бы использовать ListView вместо Scrollview, вы можете добавить элементы программно, что при добавлении их в ArrayList, который используется для отслеживания истории, то вызывающему

adapter.notifyDataSetChanged(); 

К вы можете даже сохранить указанный ArrayList в SharedPreferences, как вы хотели, или базу данных, превратив его в String (и обратно), поскольку ArrayList реализует Serializable

+0

Я хочу такой же, как Connect bot (https://play.google.com/store/apps/details?id=org.connectbot&hl=uk) на 3 снимке – MrSnaKe

+0

Итак, используйте ListView, как я описал, один с пользовательским [ ArrayAdapter] (http://developer.android.com/reference/android/widget/ArrayAdapter.html), чтобы настроить внешний вид записей в случае, если вы хотите сделать это (например, в этом приложении с зеленой точкой и т. Д.), – CyborgFish

 Смежные вопросы

  • Нет связанных вопросов^_^