In Activity called NowePomieszczenie i made function pokazdane to create new TableLayout and contain data (kosztorys_id, kosztorys_nazwa, inwestor) from database(bazakosztorys) in TableLayout's row (wiersz). Function is execute with the click button (wybierzkosztorys) like on attached image. It work good but table with database's data is not scrollable. How i can fix that ?
wyglad.setVerticalScrollBarEnabled(true); is not working
https://www.dropbox.com/s/ovqsyg990ymgsra/widok.jpg
public class NowePomieszczenie extends Activity implements 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(View 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();
}
You should put in your XML layout an ScrollView
around your layout you want to be scrollable.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
>
... your layout
</ScrollView>
You Can Use the Custom Vertical Scroll View like this in xml file
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.