0

在名为 NowePomieszczenie 的活动中,我创建了函数 pokazdane 来创建新的 TableLayout 并在 TableLayout 的行 (wiersz) 中包含来自数据库 (bazakosztorys) 的数据 (kosztorys_id、kosztorys_nazwa、inwestor)。功能是通过点击按钮(wybierzkosztorys)执行的,就像附加的图像一样。它工作得很好,但带有数据库数据的表不可滚动。我该如何解决?

wyglad.setVerticalScrollBarEnabled(true); 不管用

https://www.dropbox.com/s/ovqsyg990ymgsra/widok.jpg

公共类 NowePomieszczenie 扩展 Activity 实现 OnClickListener{

SQLiteDatabase db;
TextView textview1,textview2,textview3, textview4, textview5;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nowe_pomieszczenie);
    db=openOrCreateDatabase("baza_kosztorys", MODE_PRIVATE, null);
}

公共无效pokazdane(查看v){

final Cursor c=db.rawQuery("SELECT * from kosztorys", null);
int count= c.getCount();
c.moveToFirst();

//definicja wygladu
final TableLayout wyglad = new TableLayout(getApplicationContext());
wyglad.setVerticalScrollBarEnabled(true);
TableRow wiersz = new TableRow(getApplicationContext());

//dodanie napisu id nad kolumna id
TextView textview = new TextView(getApplicationContext());
textview.setText("DOSTĘPNE KOSZTORYSY");
textview.setTextColor(Color.BLUE);
textview.setTypeface(null, Typeface.BOLD);
textview.setPadding(20, 20, 20, 20);
wiersz.addView(textview);

wyglad.addView(wiersz);

   for(Integer j=0; j<count; j++)
     {
        //przechwytywanie pierwszej kolumny
       wiersz = new TableRow(getApplicationContext());
       wiersz.setClickable(true);
       wiersz.setId(Integer.parseInt(c.getString(c.getColumnIndex("kosztorys_id"))));


     textview = new TextView(getApplicationContext());
     textview.setText(c.getString(c.getColumnIndex("kosztorys_id")));   
     textview2 = new TextView(getApplicationContext());
     textview2.setText(c.getString(c.getColumnIndex("kosztorys_nazwa")));
     textview3 = new TextView(getApplicationContext());
     textview3.setText(c.getString(c.getColumnIndex("inwestor")));

      wiersz.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                  int idrow=  v.getId();
                   v.setBackgroundColor(Color.GRAY);  

            }       
        }); 
   //  wiersz.addView(textview);
       textview2.setPadding(20, 20, 20, 20);
       textview3.setPadding(20, 20, 20, 20);

    // wiersz.addView(textview);
       wiersz.addView(textview2);
       wiersz.addView(textview3);
       wyglad.addView(wiersz);

       c.moveToNext();
     }
     setContentView(wyglad);
     db.close();

}

4

2 回答 2

0

ScrollView您应该在您想要可滚动的布局周围放入您的 XML 布局。

 <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" 
        >

... your layout

</ScrollView>
于 2013-11-11T15:25:48.010 回答
0

您可以在 xml 文件中使用这样的自定义垂直滚动视图

垂直滚动视图:

package com.xyz.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class VerticalScrollview extends ScrollView {

    public VerticalScrollview(Context context) {
        super(context);
    }

    public VerticalScrollview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            Log.i("VerticalScrollview",
                    "onInterceptTouchEvent: DOWN super false");
            super.onTouchEvent(ev);
            break;

        case MotionEvent.ACTION_MOVE:
            return false; // redirect MotionEvents to ourself

        case MotionEvent.ACTION_CANCEL:
            Log.i("VerticalScrollview",
                    "onInterceptTouchEvent: CANCEL super false");
            super.onTouchEvent(ev);
            break;

        case MotionEvent.ACTION_UP:
            Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false");
            return false;

        default:
            Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action);
            break;
        }

        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        super.onTouchEvent(ev);
        Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction());
        return true;
    }
}
于 2013-12-05T13:00:37.043 回答