在名为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);
}
public void 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();
}
答案 0 :(得分:0)
您应该在您的布局周围添加ScrollView
您想要滚动的布局。
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
>
... your layout
</ScrollView>
答案 1 :(得分: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;
}
}