2012-04-02 24 views
0

这里是我的.xml布局文件的片段:填充滚动型与TextViews,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> 

了滚动内的TextViews是从SQL数据库填充。在ScrollView添加之前一切正常,但之后它只是出现了一个错误?

不幸的是,我不知道是哪一个错误,是不是可以从一个SQL数据库中填充值到ScrollView中的TextView中?

我想拥有一个ScrollView的原因是因为可以输出大量的数据,并且我希望它全部在同一个页面上,因此ScrollView是完美的(或者我想的)解决方案!

谢谢!

回答

0

如果你想显示来自DB的一些记录,可能最好的方法是使用ListViev而不是ScrollView。你应该在网上找到很多ListViev,CursorAdapter的例子。

+0

感谢您的帮助,认识到它,如果你简单的设置来实现的TextViews的高度为“wrap_content”,显然允许高度增加,因此ScrollView被用作输出行数增加! – 2012-04-05 16:49:54

0

在滚动视图中使用LinearLayout。 :)

<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

试试这个,通过使用ListView控件

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); 

,并在这里MyAdapter类:

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()); 


    } 


}