2012-04-02 3 views
0

Hier ist ein Ausschnitt aus meiner .xml Layout-Datei:Bestücken mit Scrolltextviews, Android Eclipse-

<ScrollView 
android:layout_width = "match_parent" 
android:layout_height = "300dp" > 
    <TextView 
     android:id="@+id/statementdatetv" 
     android:layout_width="61dp" 
     android:layout_height="300dp" 
     android:text="DATE" 
     android:textSize="10dp" /> 


    <TextView 
     android:id="@+id/statementlocationtv" 
     android:layout_width="95dp" 
     android:layout_height="300dp" 
     android:text="LOCATION" android:textSize="10dp"/> 


    <TextView 
     android:id="@+id/statementshoptypetv" 
     android:layout_width="95dp" 
     android:layout_height="300dp" 
     android:text="SHOPTYPE" android:textSize="10dp"/> 

    <TextView 
     android:id="@+id/statementpricetv" 
     android:layout_width="fill_parent" 
     android:layout_height="300dp" 
     android:text="PRICE" android:layout_weight="1" android:textSize="10dp"/> 
    </ScrollView> 

</LinearLayout> 

Die Textviews innerhalb des Scroll sind aus einer SQL-Datenbank gefüllt werden. Alles hat gut funktioniert, bevor die ScrollView hinzugefügt wurde, aber danach kam nur ein Fehler auf?

Leider weiß ich nicht, welchen Fehler, ist es einfach nicht möglich, die Werte aus einer SQL-Datenbank in eine TextView, die in einem ScrollView ist, zu füllen?

Der Grund, warum ich eine ScrollView haben möchte, ist, weil viele Daten ausgegeben werden können, und ich möchte, dass alle auf der gleichen Seite sind, daher war ein ScrollView die perfekte (oder so dachte ich) Lösung!

Danke!

Antwort

0

Wenn Sie einige Datensätze aus der Datenbank anzeigen möchten, verwenden Sie am besten ListViev anstelle von ScrollView. Sie sollten viele Beispiele für ListViev, CursorAdapter im Netz finden.

+0

Danke für die Hilfe realisiert, dass es einfach, wenn Sie die eingestellte getan werden kann, TextViews Höhe zu "wrap_content", offensichtlich erlaubt die Höhe zu erhöhen, daher die ScrollView als die Anzahl der Zeilen verwendet werden, um zu erhöhen! –

0

Verwenden Sie eine LinearLayout-Bildlaufansicht. :)

<ScrollView 
android:layout_width = "match_parent" 
android:layout_height = "300dp" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:orientation="vertical" 

    > 
    <TextView 
     android:id="@+id/statementdatetv" 
     android:layout_width="61dp" 
     android:layout_height="300dp" 
     android:text="DATE" 
     android:textSize="10dp" /> 


    <TextView 
     android:id="@+id/statementlocationtv" 
     android:layout_width="95dp" 
     android:layout_height="300dp" 
     android:text="LOCATION" android:textSize="10dp"/> 


    <TextView 
     android:id="@+id/statementshoptypetv" 
     android:layout_width="95dp" 
     android:layout_height="300dp" 
     android:text="SHOPTYPE" android:textSize="10dp"/> 

    <TextView 
     android:id="@+id/statementpricetv" 
     android:layout_width="fill_parent" 
     android:layout_height="300dp" 
     android:text="PRICE" android:layout_weight="1" android:textSize="10dp"/> 
</LinearLayout> 
    </ScrollView> 
1

dieses Versuchen, von Listview mit

MyAdapter adapteres; 
list = (ListView) findViewById(R.id.grp_list); 
db = new DatabaseHelper(this); 
contacts = db.getAllContacts(); 
adapteres = new MyAdapter(getBaseContext(), (ArrayList<Contact>) contacts); 
list.setAdapter(adapteres); 

und hier MyAdapter Klasse:

public class MyAdapter extends BaseAdapter{ 
    Button btn; 
    @SuppressWarnings("unused") 
    private Context context; 
    private ArrayList<Contact> contact; 
    private LayoutInflater mInflater; 


    public MyAdapter(Context context, ArrayList<Contact> contacts) { 
     this.context = context; 
     this.contact = contacts; 
     mInflater = LayoutInflater.from(context);  
    } 

    public int getCount() { 

     return contact.size(); 
    } 

    public Object getItem(int position) { 

     return contact.get(position); 
    } 

    public long getItemId(int position) { 

     return position; 
    } 

    public View getView(int pos, View view, ViewGroup parent) { 
     if (view == null) { 
      view = mInflater.inflate(R.layout.group_row, parent, false); 
     } 

     Contact item = contact.get(pos); 


     TextView name = (TextView) view.findViewById(R.id.group_name); 
     name.setText(item.getName()); 


    } 


}